I have an object of class Foo:
class Foo extends Bar {
protected $a;
protected $b;
}
$obj = new Foo();
What I want (and have) to do is cast this object to an array, like this:
$arr = (array)$obj;
Is there any magic (or not magic :)) method that is being called at this moment? Or is there any other way to intercept it? I know I can write a simple method, eg. asArray()
in Foo, but I'm looking for some more "native" PHP ways.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…