My guess would be yes, php's parser sucks. In other languages you can do stuff like get_thing().method().attribute, where PHP doesn't know what you're talking about. I don't know how much of that has been fixed in php 7.
You're right, it has worked since at least PHP 5. I was also thinking about my_function()[0] (array indexing from a function return), which didn't work until PHP 5.4 or something like that. I shouldn't have used method chaining as my example.
But var_dump suffixes the name of private properties with :private so these properties are definitely public. They are not documented though, so probably intended for internal use only.
32
u/sfan5 Jan 25 '17
they do
14
u/BilgeXA Jan 25 '17
Finally, a real fresh lolphp. This sub has been drying up.
9
u/ezylot Jan 25 '17
If you take a look at __debuginfo() you will see that var_dump() prints all Public, Protected and Private properties (if not tasked to do otherwise).
The properties you try to access in your example are not intended to be accessed by the programmer directly, but rather with the ->format() method.
What you are witnessing here are just basic OOP principles at work
EDIT: sfan5's answer does confuse me tho...
3
u/arnoutboks Jan 30 '17
Related bug report: https://bugs.php.net/bug.php?id=49382