开发者

Is it possible to implement an array-like object in PHP?

I want to implement an object that behaves like 开发者_C百科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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜