php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63317 Add alternate, more logical foreach syntax
Submitted: 2012-10-20 11:19 UTC Modified: 2013-03-15 14:24 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: evertvandansen at ymail dot com Assigned:
Status: Wont fix Package: Unknown/Other Function
PHP Version: 5.4.8 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
42 + 48 = ?
Subscribe to this entry?

 
 [2012-10-20 11:19 UTC] evertvandansen at ymail dot com
Description:
------------
This is a very low priority request for adding an alternate foreach syntax. Right 
now we write something like:
foreach ($cats as $cat)
Which is fine, but neither semantically nor grammatically correct. I would propose 
that 
foreach ($cat in $cats) or foreach ($cat from $cats)
makes much more sense and is more readable. Not just from a grammatical point of 
view, but also because that way the actual identifier you use in the iteration is 
placed first.
The existing syntax should obviously remain, it is simply an alternate syntax, not 
meant to substitute.
Again, it is not a very important request as it does not improve PHP technically, 
only in regards to readability and (for some) usability.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-15 14:24 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2013-03-15 14:24 UTC] nikic@php.net
Don't think this will happen as it doesn't have any (quantifiable) advantages over the current syntax but would a) introduce two ways to do the same thing and b) add a new keyword that is very likely be currently in use. Marking Won't Fix.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 06:01:33 2024 UTC