Req #70440 [NEW]: Support strict switch
From: david dot proweb at gmail dot com
Operating system:
PHP version: Next Minor Version
Package: Scripting Engine problem
Bug Type: Feature/Change Request
Bug description:Support strict switch
Description:
------------
Currently switch() are loose (as said on doc), but it should be strict
by using a keyword. It's need to avoid somekind of hacks:
Suggestion:
strict switch ($value) ...
switch strict ($value) ...
Or, is possible improve a lot the strict by accept an operator. It
should compare the switch value with case value:
switch == $value ... or
switch == ($value) ...
switch === $value ...
switch >= $value ...
switch < $value ...
So you can do something like that:
switch >= $strength {
case 0: return 'weak';
case 40: return 'medium';
case 80: return 'strong';
case 100: return 'perfect';
}
Currently it's possible by 'hacking' that:
switch (true) {
case $strength >= 0: return 'weak';
case $strength >= 40: return 'medium';
case $strength >= 80: return 'strong';
case $strength >= 100: return 'perfect';
}
--
Edit bug report at https://bugs.php.net/bug.php?id=70440&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70440&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70440&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70440&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70440&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70440&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70440&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70440&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70440&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70440&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70440&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70440&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70440&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70440&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70440&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70440&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70440&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70440&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70440&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70440&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70440&r=mysqlcfg
Thread (4 messages)
- david dot proweb at gmail dot com