So I'm working with some external PHP code that I don't have the full source for. I am using reflection to work out callable methods, etc.
They have a class like so:
class SpecialArray implments \ArrayAccess
{
public function offsetExists($index){}
public function offsetGet($index){}
public function offsetSet($index, $value){}
public function offsetUnset($index){}
}
So logically I can foreach(SpecialArray)
, that's fine.
However in the code I can somehow do count(SpecialArray)
and get the correct count, eg if there are 5 elements in the SpecialArray doing count(SpecialArray)
will return 5!
However there isn't a count
method in the class, nor does the class implement Countable
Calling SpecialArray->count()
also fails with Call to undefined method
Does anyone have any ideas how they may be doing this voodoo magic??
Full \ReflectionClass::export()
Class [ class ThirdParty\SpecialArray implements ArrayAccess ] {
- Constants [0] {
}
- Static properties [1] {
Property [ public static $_metadata ]
}
- Static methods [1] {
Method [ static public method &getMetadata ] {
- Parameters [0] {
}
}
}
- Properties [0] {
}
- Methods [5] {
Method [ public method offsetExists ] {
- Parameters [1] {
Parameter #0 [ $index ]
}
}
Method [ public method offsetGet ] {
- Parameters [1] {
Parameter #0 [ $index ]
}
}
Method [ public method offsetSet ] {
- Parameters [2] {
Parameter #0 [ $index ]
Parameter #1 [ $value ]
}
}
Method [ public method offsetUnset ] {
- Parameters [1] {
Parameter #0 [ $index ]
}
}
Method [ public method fetch ] {
- Parameters [1] {
Parameter #0 [ $index ]
}
}
}
}