php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72148 foreach-else construct
Submitted: 2016-05-04 07:42 UTC Modified: 2016-05-04 13:26 UTC
From: jdmnst at gmail dot com Assigned:
Status: Duplicate Package: *General Issues
PHP Version: Irrelevant OS: All
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 !
Your email address:
MUST BE VALID
Solve the problem:
38 + 32 = ?
Subscribe to this entry?

 
 [2016-05-04 07:42 UTC] jdmnst at gmail dot com
Description:
------------
foreach-else construct, that if foreach-element is empty (or not iterable).

Test script:
---------------
$foo = [];

foreach ($foo as $bar) {
   echo $bar;
] else {
   echo 'no bar';
}

Expected result:
----------------
no bar

Actual result:
--------------
PHP Parse error:  syntax error, unexpected 'else' (T_ELSE) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-04 08:10 UTC] stas@php.net
-Package: PHP Language Specification +Package: *General Issues
 [2016-05-04 13:26 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2016-05-04 13:26 UTC] nikic@php.net
Duplicate of bug #46240 for foreach specifically and bug #26411 for loops generically, which is marked as Won't Fix as the RFC https://wiki.php.net/rfc/loop_or has been declined.
 [2016-05-10 13:58 UTC] must at be dot valid
You should really reconsider... it's much more useful than most of the other features you implemented in the past.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 19:01:31 2024 UTC