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
Hello,
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
--
--
Etienne Kneuss
http://www.colder.ch
Hello,
Hello,
ArrayObject extends the handler responsible for giving you such
information. So it might very well be a bug.You should report it!
Best,
Thanks Etienne, I went ahead and made a bug report and patch here:
https://bugs.php.net/bug.php?id=55406
-Chris