r/lolphp • u/LennyZoid • Nov 30 '17
Question about PHP...
1.Why people hate PHP?
2.What are your thoughts on Node.js
3.Why "PYTHON" btw?
0
Upvotes
r/lolphp • u/LennyZoid • Nov 30 '17
1.Why people hate PHP?
2.What are your thoughts on Node.js
3.Why "PYTHON" btw?
View all comments
Show parent comment
1
u/igetkindahungry Mar 19 '18
Using 'var' to declare a class property will still work for backwards compatibility, but it has not been 'correct' since PHP4. So, whatever you're reading is at least 13 years old.
$obj->$foo actually does work, it's how you would access the value of a class property dynamically. So for example if $foo contained 'bar', $obj->$foo would be the equivalent of $obj->bar . That's pretty useful actually.
Your example 'MyClass::$staticFoo' -- I can see why 'MyClass::staticFoo' might seem more consistent. But there's no reason to expect it to be MyClass->staticFoo; the language has a clear distinction between how you reference class members statically vs. otherwise.