Hello, On Tue, Jan 20, 2015 at 7:47 AM, Marcio Almada <marcio.w...@gmail.com> wrote:
> Hi, > > Mike, the use of "in" as `for ($var in $object) {};` could be the > subject for another distinct RFC since it's doing something different > from the original proposal: > > var_dump("PHP" in ["PHP", "C", "Java"]); // true > It is indeed different but ever so slightly, a for loop in this case cannot handle a single argument of true and would cause a parse error. Therefore for ("PHP" in ["PHP, "C", "Java"]) could be handled differently. Again, my main point is that due to other languages the in operator itself also correlates to for ($var in $container), I understand having an additional RFC but this is indeed the place for discussion of such things. Also FYI - in the future please try not to top post and instead post under where you are commenting as it makes it more difficult for people coming later to the thread to see the scope of the conversation. Regards, Mike > > 2015-01-20 10:41 GMT-03:00 Mike Willbanks <pen...@gmail.com>: > > Hello Pierre, Andrea and Niklas, > > > > On Mon, Jan 19, 2015 at 11:35 PM, Pierre Joye <pierre....@gmail.com> > wrote: > > > >> On Tue, Jan 20, 2015 at 6:15 AM, Andrea Faulds <a...@ajf.me> wrote: > >> >> On 20 Jan 2015, at 03:30, Mike Willbanks <pen...@gmail.com> wrote: > >> >> > >> >> I am very familiar with the in operator. However, the > implementation > >> >> would be incomplete without handling loops via the in operator. Many > >> >> people when seeing an in operator also think of JavaScript. In that > >> case > >> >> the in operator iterates over properties. As such in PHP we should > be > >> able > >> >> to iterate over associative arrays should the syntax be added. > >> >> > >> > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in > >> > > >> > Why? We already have foreach/as which does exactly that, and unlike JS > >> which added for/of, there’s nothing wrong with PHP’s foreach so we don’t > >> need support for a new symbol. > >> > >> Indeed, exactly same feature. > > > > > > It certainly is the same feature from the foreach perspective. I'm not > > against leaving it out, however, it would be much like the in operator > thus > > providing some additional syntax sugar. Many people that often program > in > > JavaScript are used to having: > > array.forEach(function()), for (property in object), etc. > > > > From my perspective it would seem like a hole in the implementation for > it > > to be missing but that is also due to having such a split of time between > > the two languages. Take for instance python utilizing the same thing: > > > > for variable in expression: > > ... code > > ... > > > > as well as ruby: > > > > for variable [, variable ...] in expression [do] > > code > > end > > > > Ultimately, I would feel that having the in operator would also create > the > > expectation that in PHP we would be able to achieve the following: > > > > for ($var in $array) {} and/or for ($var in $object) {}; > > > > Certainly foreach is more rich but I believe based on other languages and > > paradigms that this would be something people would request and expect if > > the in operator was to make it into PHP 7. > > > > Regards, > > > > Mike >