Re: The behavior of get_object_vars and array casting when extending ArrayObject

From: Date: Thu, 11 Aug 2011 18:58:42 +0000
Subject: Re: The behavior of get_object_vars and array casting when extending ArrayObject
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-54509@lists.php.net to get a copy of this message
Hello, On Thu, Aug 11, 2011 at 20:54, Chris Stockton <chrisstocktonaz@gmail.com> wrote: > 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. ArrayObject extends the handler responsible for giving you such information. So it might very well be a bug. You should report it! Best, > > --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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Etienne Kneuss http://www.colder.ch

« previous php.internals (#54509) next »