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
 [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-2019 The PHP Group
All rights reserved.
Last updated: Thu May 23 23:01:26 2019 UTC