I want to implement an object that behaves like an array. It should be used in this way:
$var = new CustomCollection(retrieveFromWebService());
echo $var[0]; // legal
$var[0] = 'a'; // illegal
Can this be done in PHP, using magic methods or another mechanism?
Your CustomCollection class will need to implement the built-in ArrayAccess interface.
See also: http://code.google.com/p/phpraise/source/browse/trunk/phpraise/core/collection/RaiseCollection.php
I think ArrayAccess is what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With