Req #26411 [Com]: while {} else {}

From: Date: Tue, 27 Jun 2017 16:55:21 +0000
Subject: Req #26411 [Com]: while {} else {}
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209709@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID:                 26411
 Comment by:         bensor987 at neuf dot fr
 Reported by:        php at bellytime dot com
 Summary:            while {} else {}
 Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        *
 Block user comment: N
 Private report:     N

 New Comment:

Plus, consider the following (bad) code :
<?php
$bool = true;
$rand = rand(1, 5);

if ($bool)
  while ($rand != 4) 
    $rand = rand(1, 5);
else
  echo '!bool';

If "else" for loops is implemented, the behaviour of this code will change. I'm sure
there are a lot of code like this. That's another reason people don't like this new use
for "else".


Previous Comments:
------------------------------------------------------------------------
[2017-06-27 16:21:44] bensor987 at neuf dot fr

This syntax is causing problems for some because it violates the KISS principles. Since
"else" is used for conditions, and since you can write conditions and loops without curly
brackets, it could cause confusion to a lot of people.

I proposed "iterated" (if at least 1 iteration) and "none" ("else") as
replacements, but this request has been rejected shortly after...

------------------------------------------------------------------------
[2017-06-27 10:46:32] php at pointpro dot nl

This syntax would indeed be great. I see that the vote was not passed at the RFC, but I don't
see any argumentation why.

Other languages don't have it is not true, and also not a reason to not add it.

What are arguments against having such a useful construct?

------------------------------------------------------------------------
[2017-06-17 16:28:03] rageclick at gmail dot com

I almost never join conversations or write comments online but I would also love to see this feature
as well. It's just nicer, easier to look at and it uses less code which is what I go for.
However... if there is a reason behind why you won't do this, I would understand.

while ($result = $get->fetch_assoc()) {
  $in=1;
  echo 'Something';
}
if(!$in){ echo 'Nothing'; }

WHEN I could be doing this

while ($result = $get->fetch_assoc()) {
       echo 'Something'; 
}else{ echo 'Nothing'; }

------------------------------------------------------------------------
[2016-05-10 13:56:48] asd at asd dot asd

Hey, it's an awesome feature everyone would like. Let's reject it!

------------------------------------------------------------------------
[2016-05-04 13:26:08] nikic@php.net

Related To: Bug #72148

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=26411


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


Thread (28 messages)

« previous php.bugs (#209709) next »