|  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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jdmnst at gmail dot com
New email:
PHP Version: OS:


 [2016-05-04 07:42 UTC] jdmnst at gmail dot com
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) 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-04 08:10 UTC]
-Package: PHP Language Specification +Package: *General Issues
 [2016-05-04 13:26 UTC]
-Status: Open +Status: Duplicate
 [2016-05-04 13:26 UTC]
Duplicate of bug #46240 for foreach specifically and bug #26411 for loops generically, which is marked as Won't Fix as the RFC 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-2022 The PHP Group
All rights reserved.
Last updated: Sun Aug 14 03:05:46 2022 UTC