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 #185991 is a reply to message #185990] Sat, 24 May 2014 12:37 Go to previous messageGo to previous message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma:
Senior Member
Jerry Stuckle wrote:

> On 5/24/2014 6:05 AM, Christoph Michael Becker wrote:
>> kurtk(at)pobox(dot)com wrote:
>>
>>> The documentation for ArrayAccess (at
>>> http://www.php.net/manual/en/class.arrayaccess.php) doesn't show it
>>> implementing Traversable. Nevertheless, you can still use any class
>>> you write that implements ArrayAccess in a foreach loop.
>>>
>>> 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>.
>>
>
> But that is an entirely different access to what Kurt is talking about.
>
> Kurt is discussing how to transverse an array within an object; your
> page discusses how to transverse public data members in an object. But
> good OO practices says all data members should be private.

To traverse an array which is a member of an object $o with foreach($o
....), the object's class has to implement IteratorAggregate or Iterator,
not ArrayAccess.

--
Christoph M. Becker
[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 00:00:36 GMT 2024

Total time taken to generate the page: 0.11805 seconds