#48192 [NEW]: if structure inherit else
| From: | skds1433 at hotmail dot com | Date: | Fri, 08 May 2009 17:05:00 +0000 |
| Subject: | #48192 [NEW]: if structure inherit else | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-136986@lists.php.net to get a copy of this message | ||
From: skds1433 at hotmail dot com
Operating system: vista
PHP version: 5.2.9
PHP Bug Type: Feature/Change Request
Bug description: if structure inherit else
Description:
------------
I'm requesting a way for the 'if' control struction to be able to inherit
'else' control structures, in a similar matter as below. This will help
prevent duplicated code, and help keep it clean and uncluttered.
I've included an 'expected_equivalent', which is actually less code than
in the 'routine' function. However, if a developer wishes to include a
greater diveristy, it can become a real advantage to use just one 'else'.
Additionally, it I think it would be benefitional for 'if' control
structure to make it more 'complete'.
I also understand there are already numerous ways to do this, which have
the same result and possibly even less code. Nonetheless, I believe this
way could be a better, easier way for certain situations.
Reproduce code:
---------------
<?php
function routine ($foo, $bar)
{
if ($foo === 0) echo "foo is 0\n";
elseif ($foo === 1)
if ($bar === 0) echo "bar is 0\n";
elseif ($bar === 1) echo "bar is 1\n";
else echo "foo: ".$foo.", bar: ".$bar."\n";
# else would apply to both elseif
}
function expected_equivalent ($foo, $bar)
{
if ($foo === 0) echo "foo is 0\n";
elseif ($foo === 1 && $bar === 0) echo "bar is 0\n";
elseif ($foo === 1 && $bar === 1) echo "bar is 1\n";
else echo "foo: ".$foo.", bar: ".$bar."\n";
}
routine (0, 1);
routine (1, 0);
routine (1, 1);
routine (2, 1);
routine (1, 2);
routine (2, 2);
?>
Expected result:
----------------
foo is 0
bar is 0
bar is 1
foo: 2, bar: 1
foo: 1, bar: 2
foo: 2, bar: 2
Actual result:
--------------
foo is 0
bar is 0
bar is 1
foo: 1, bar: 2
--
Edit bug report at http://bugs.php.net/?id=48192&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48192&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48192&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48192&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=48192&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48192&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=48192&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=48192&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=48192&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=48192&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=48192&r=support
Expected behavior: http://bugs.php.net/fix.php?id=48192&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=48192&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=48192&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=48192&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48192&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48192&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=48192&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=48192&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=48192&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=48192&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=48192&r=mysqlcfg