Req #72148 [Opn->Dup]: foreach-else construct

From: Date: Wed, 04 May 2016 13:26:08 +0000
Subject: Req #72148 [Opn->Dup]: foreach-else construct
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200889@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72148&edit=1

 ID:                 72148
 Updated by:         nikic@php.net
 Reported by:        jdmnst at gmail dot com
 Summary:            foreach-else construct
-Status:             Open
+Status:             Duplicate
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   All
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2016-05-04 07:42:38] 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) 


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72148&edit=1


Thread (1 message)

  • nikic@php.net
  • Unknown Message
    • nikic@php.net
« previous php.bugs (#200889) next »