Search code examples
phparraysspl

PHP's SPL: Do its interfaces involving arrays cover all array properties?


Would it be possible to write a class that is virtually indistinguishable from an actual PHP array by implementing all the necessary SPL interfaces? Are they missing anything that would be critical?

I'd like to build a more advanced Array object, but I want to make sure I wouldn't break an existing app that uses arrays everywhere if I substituted them with a custom Array class.


Solution

  • The only problems i can think of are the gettype() and the is_array() functions. Check your code for

    gettype($FakeArray) == 'array' 
    is_array($FakeArray)
    

    Because although you can use the object just like an array, it will still be identified as an object.