Today while evaluating PHP 5.3 I stumbled about a subtle BC break which has already been introduced in PHP 5.2.4. Consider the following code:
The result with PHP < 5.2.4:
E:\php\tests>php get_object_vars.php
array(3) {
["public"]=>
string(6) "public"
["protected"]=>
string(9) "protected"
["private"]=>
string(7) "private"
}
array(3) {
["public"]=>
string(6) "public"
["protected"]=>
string(9) "protected"
["private"]=>
string(7) "private"
}
And the result with PHP >= 5.2.4:
E:\php-5.2.4-Win32>php ../php/tests/get_object_vars.php
array(3) {
["public"]=>
string(6) "public"
["protected"]=>
string(9) "protected"
["private"]=>
string(7) "private"
}
array(2) {
["public"]=>
string(6) "public"
["protected"]=>
string(9) "protected"
}
Spotted the difference? In the second array the private member is not there any more. While this may be correct from the object-oriented point of view I wonder whether this really must have been fixed in a bugfix release - ok, it is obviously a
bug, but I would consider the change a BC break as well. On the other hand no one really complained until now.
However the new behaviour is a bit sad because this means you can not implement a method in your base class that returns a list of all members of any arbitrary child class regardless of their visibility including their value. (Well you can, but casting the object to an array and fixing the keys is a bit messy.) Good bye, my simple __toString() method in the base class...