Undocumented change: order of returned parameters in get_object_vars() differs from previous versions
Description
The following code:
<?php
class TestA extends TestB
{
protected $foo;
public function test()
{
return get_object_vars($this);
}
}
class TestB
{
protected $bar;
}
$foo = new TestA();
var_dump($foo->test());
Resulted in this output:
array(2) {
["bar"]=>
NULL
["foo"]=>
NULL
}
But in PHP < 8.1.0 I got this output instead:
array(2) {
["foo"]=>
NULL
["bar"]=>
NULL
}
PHP Version
PHP >= 8.1.0
Operating System
No response
I can't see any recent changes in get_object_vars that would explain this. Maybe it has something to do with Dmitrys changes about inheritance? The order doesn't seem to be documented as of yet, so it might be best to simply update the documentation accordingly.
@iluuu1994 @beephotography maybe it's covered here https://www.php.net/manual/en/migration81.other-changes.php#migration81.other-changes.functions.core
The order of properties used in foreach, var_dump(), serialize(), object comparison, etc. was changed. Properties are now ordered naturally according to their declaration and inheritance. Properties declared in a base class are going to be before the child properties.
@pospjan Yes, thank you!