FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » ArrayAccess interface, Traversable interface and foreach
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: ArrayAccess interface, Traversable interface and foreach [message #185996 is a reply to message #185989] Tue, 27 May 2014 18:59 Go to previous messageGo to previous message
Adam Harvey is currently offline  Adam Harvey
Messages: 25
Registered: September 2010
Karma:
Junior Member
On Sat, 24 May 2014 12:05:02 +0200, Christoph Michael Becker wrote:

> kurtk(at)pobox(dot)com wrote:
>
>> This seems like an oversight in the documentation--unless I am missing
>> something?
>
> You can use any object (whether it is an instance of a class that
> implements Traversable or not) in a foreach loop, see
> <http://www.php.net/manual/en/control-structures.foreach.php>.

Yep, this is why objects that implement ArrayAccess still work with
foreach without implementing Traversable.

ArrayAccess and Traversable are technically different things: Traversable
provides a way to control iteration, whereas ArrayAccess is only for
array-style dereferencing via $object['key']. In practice, classes that
need to imitate arrays will need to implement both (probably by extending
a class such as ArrayObject that implements both interfaces).

Adam
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: mysqli fetch_assoc() straight to array
Next Topic: Pthread with amazon sns
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun May 19 02:56:16 GMT 2024

Total time taken to generate the page: 0.04348 seconds