Casting object to array - any magic method being called?

前端 未结 6 1831
梦谈多话
梦谈多话 2020-12-10 00:44

I have an object of class Foo:

class Foo extends Bar {
    protected $a;
    protected $b;
}

$obj = new Foo();

What I want (and have) to d

6条回答
  •  感动是毒
    2020-12-10 01:12

    You can have the class implement the ArrayAccess interface. This will allow you to treat the object like an array without casting and you get total control over how the members are used.

提交回复
热议问题