Check out Scrivo

Do you want to try out Scrivo? Then here's a demo for you that does not just get your feet wet but lets you plunge right in.

Contact us

For more information, please contact us. We're happy to help you out!

Next Sep 21 Previous

Item 547231

You want to create you're own array objects that can be used in PHP array functions such as array_key_exists(), asort() and array_keys(). So your array class:

A: implements Countable
B: implements Countable and ArrayAcces
C: implements Countable, ArrayAcces and Iterator
D: extends ArrayObject
E: none of the above

Answer

Well, you're out of luck and I guess this is a big disappointment for all of you OO junkies out there (at least it was for me). PHP objects that implement all array interfaces are not considered arrays but objects by PHP. This means that you cannot apply PHP's rich library of array functions to your own array classes: you only can use those function that directly map to the functions you've implemented (f.i. count(), current(), key() or next()).

Extending ArrayObject is not going to help you either: it's an object that implements all array interfaces but still it's not a PHP array.

So the correct answer is E but actually it's worse: there is no way you can create array-like objects that can be used as PHP arrays.