The behavior of get_object_vars and array casting when extending ArrayObject

From: Date: Thu, 11 Aug 2011 18:54:36 +0000
Subject: The behavior of get_object_vars and array casting when extending ArrayObject
Groups: php.internals 
Request: Send a blank email to internals+get-54508@lists.php.net to get a copy of this message
I was curious if this behavior was expected, it caught me by surprise. A base object I use extends ArrayObject, that class is extended heavily throughout my code and I recently wanted to use get_object_vars, but noticed it returning an empty array. I do not expect get_object_vars to return the properties I set via a ArrayObject, but I would expect explicitly defined properties in sub-classes and even in the ArrayObject extending class to be returned. Is this thinking correct? If everyone agrees this is a bug I can report it and write a patch assuming its not a deep complicated problem. --Code class TestOne { public $TestOne_1 = 1; } class TestTwo extends ArrayObject { public $TestTwo_1 = 1; } class TestThree extends TestTwo { public $TestThree_1 = 1; } $t1 = new TestOne; var_dump((array) $t1, get_object_vars($t1)); $t2 = new TestTwo; var_dump((array) $t2, get_object_vars($t2)); $t3 = new TestThree; var_dump((array) $t3, get_object_vars($t3)); --Produces array(1) { ["TestOne_1"]=> int(1) } array(1) { ["TestOne_1"]=> int(1) } array(0) { } array(0) { } array(0) { } array(0) { } Thanks, -Chris

« previous php.internals (#54508) next »