Re: Re: Allow Iterator to be used with current, next, reset, key functions

From: Date: Tue, 01 Nov 2016 02:13:11 +0000
Subject: Re: Re: Allow Iterator to be used with current, next, reset, key functions
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-96687@lists.php.net to get a copy of this message
On 10/31/16 9:02 AM, Andrea Faulds wrote: > > A concern that strikes me is that it's possible some existing code uses > these functions precisely because they don't support Iterators, because > the author wants to iterate over an object's properties. > I hadn't thought about that particular use case. I also hadn't ever tried using these functions on non-arrays before I recently attempted using them with an Iterator. > What would be the proposed alternative in that case? Reflection? I would think that Reflection would be necessary to get the private/protected properties, but these functions currently allow iteration over private/protected properties of an object. This should be limited to public properties similar to the way foreach is limited. But that's another issue. > I think it's unfortunate that PHP has two iteration behaviours for > objects, namely iterating over properties, and custom iterators. I think > those ought to be separate, rather than the latter overriding the former. As a user it came as a surprise that I couldn't use an Iterator where an array was being used, as they are used interchangeable in some other contexts. I'll also admit that I don't normally read the docs until I have problems. The behavior with passing objects to those functions is only documented by a user comment. Dave -- David Lundgren dlundgren@syberisle.net GPG: 0x26F54D7F

« previous php.internals (#96687) next »