What do the symbols `->`, `::`, `$this`, `self`, `parent` mean in PHP? Complete syntax reference
Hello everyone! I just started learning PHP and I keep getting confused about these arrows, colons, and keywords. I'm reading someone else's code and I see:\n\n```php\n$user->getName();\nUser::create();\n$this->name = 'John';\nself::VERSION;\nparent::__construct();\n```\n\nI can't understand when to use `->` and when to use `::`. What's the difference between `$this`, `self`, and `parent`? Why in one case they write `$user->method()`, and in another `User::method()`?\n\nI understand that this is somehow related to objects and classes, but the specific rules escape me. Can you explain in simple terms, with examples, when to use which syntax? I would be very grateful for a complete reference with explanations, so I can look it up like a cheat sheet.\n\nThanks in advance!
No answers yet.
Log in to leave an answer
Blogs