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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jdmnst at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sun Dec 22 12:01:30 2024 UTC