# The behavior of get_object_vars and array casting when extending ArrayObject

- Thread: https://externals.io/message/54508
- Original archive: https://news-web.php.net/php.internals/54508
- Started by Chris Stockton on 2011-08-11T18:54:36+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #54508 — Chris Stockton — 2011-08-11T18:54:36+00:00

URL: https://externals.io/message/54508#54508

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

---

## #54509 — Etienne Kneuss — 2011-08-11T18:58:42+00:00

URL: https://externals.io/message/54508#54509 · In reply to: #54508

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

---

## #54511 — Chris Stockton — 2011-08-11T20:42:57+00:00

URL: https://externals.io/message/54508#54511 · In reply to: #54509

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
