Req #51743 [NEW]: An improvement to control blocks, `else` on loop

From: Date: Tue, 04 May 2010 22:09:05 +0000
Subject: Req #51743 [NEW]: An improvement to control blocks, `else` on loop
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150183@lists.php.net to get a copy of this message
From: Operating system: ALL PHP version: Irrelevant Package: Unknown/Other Function Bug Type: Feature/Change Request Bug description:An improvement to control blocks, else on loop Description: ------------ It would be totally kickin' if we could have 'ELSE' on a loop control. for example, my current code: ----------------------- $results = mysql_query($sql); if(!$results || mysql_errno()) die("gaaah!"); if(mysql_num_rows()<1) echo "<tr><td>No results found</td></tr>"; else { while($row = mysql_fetch_assoc($result)) { //echo rows of a table or something... } } ---------------------- could be: ---------------------- $results = mysql_query($sql); if(!$results || mysql_errno()) die("gaaah!"); while($row = mysql_fetch_assoc($result)) { //echo rows of a table or something... } ELSE { echo "<tr><td>No results found</td></tr>"; } ---------------------- The definition of an else on a loop would be "If the initial loop condition fails in such a way that the loop never iterates (once or more), then the ELSE block will be executed instead. Loops supported would be while, for, and foreach This would be great for debugging as well, when you're trying to figure out why things never executed, if there was an 'ELSE { echo " -DEGUB: never entered lool"; } on loops that must be entered it would tip programmer's off right away. just think about it: foreach($items as $item) { echo "Item: $item\r\n"; } else { echo "No items found.\r\n"; } -- Edit bug report at http://bugs.php.net/bug.php?id=51743&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51743&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51743&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51743&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51743&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51743&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51743&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51743&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51743&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51743&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51743&r=support Expected behavior: http://bugs.php.net/fix.php?id=51743&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51743&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51743&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51743&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51743&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51743&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51743&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51743&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51743&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51743&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51743&r=mysqlcfg

« previous php.bugs (#150183) next »