Given the following class, why does get_object_vars
return an empty array? This only happens when I'm extending PHP's ArrayObject
but in the documentation I can't manage to find out the reason for this behavior.
class Test extends ArrayObject
{
public $foo;
public $bar;
public function setFooBarValues( array $values )
{
$this->foo = !empty( $values['foo'] ) ? $values['foo'] : null;
$this->bar = !empty( $values['bar'] ) ? $values['bar'] : null;
}
public function getArrayCopy()
{
return get_object_vars( $this );
}
}
Running the following code that first sets the object's values shows that get_object_vars
does not return the object's properties.
$object = new Test( array( 'lemon' => 1, 'orange' => 2, 'banana' => 3, 'apple' => 4 ) );
$object->setFooBarValues( array( 'foo' => 'x', 'bar' => 'y' ) );
var_dump( $object->getArrayCopy() );
Expected result:
array(2) {
["foo"]=>
string(1) "x"
["bar"]=>
string(1) "y"
}
Actual result:
array(0) {
}