get_object_vars() Does Not Work On ArrayObject¶
Until PHP 7.4, ArrayObject used to export its properties as they were defined in the array. Since then, ArrayObject does not export any property anymore. They are still accessible via the normal property syntax, just not with get_object_vars() anymore.
PHP code¶
<?php
// Illustration courtesy of Doug Bierer
$obj = new ArrayObject(['A' => 1,'B' => 2,'C' => 3]);
var_dump($obj->getArrayCopy());
var_dump(get_object_vars($obj));
//var_dump((array) $obj);
?>
Before¶
array(3) {
[A]=>
int(1)
[B]=>
int(2)
[C]=>
int(3)
}
array(3) {
[A]=>
int(1)
[B]=>
int(2)
[C]=>
int(3)
}
After¶
array(3) {
[A]=>
int(1)
[B]=>
int(2)
[C]=>
int(3)
}
array(0) {
}
PHP version change¶
This behavior changed in 7.4