What does the 'var' keyword do in PHP and why is it needed?
Hello everyone! I just started learning PHP, and I have a question about the `var` keyword. I came across some old code where `var` is used inside a class to declare properties:\n\n```php\nclass User {\n var $name;\n var $email;\n \n function __construct($name, $email) {\n $this->name = $name;\n $this->email = $email;\n }\n}\n```\n\nIn modern tutorials, I see everyone using `public`, `private`, or `protected`. But `var` also works — the code runs without errors. I don't understand: why is `var` needed if there are access modifiers? Maybe it's just an outdated synonym for `public`? Or does it have some special features? Why can it still be used if it's considered bad practice? I would appreciate a detailed explanation with examples.
No answers yet.
Log in to leave an answer
Blogs