Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports

[2016-07-25 19:17 UTC] dave at mudsite dot com

Switch()'s take inputs and let you have cases for single option of the element. To preform ranges I'm not certain a switch() would be the right idea. I'm not sure having the 'hacked' switch is any better, or easier to read than:
if ($strength >= 0) return 'weak';
elseif ($strength >= 40) return 'medium';
elseif ($strength >= 80) return 'strong';
elseif ($strength >= 100) return 'perfect';
^^^ is easier to read imo, and doesn't distort what switch() should be doing.

[2017-02-08 09:21 UTC] arossi dot gweb at gmail dot com

A strict switch operator would be very useful to check for functions that return mixed integers and booleans. Example:
switch (a_function_that_returns_int_or_bool()) {
case 2:
// do something
break;
case 3:
// do something
break;
case true:
default:
// do something
break;
}
This switch statement always evaluates to the first case if the return value of the function is (bool) true. The same happens if you put the "case true" as the first case.
We really need a "strict switch".

Thank you for your interest in PHP and for submitting a feature request. Please be aware that due to the magnitude of change this request requires, it would be necessary to discuss it on PHP Internals list (internals@lists.php.net) as an RFC. Please read the guide about creating RFCs here:
https://wiki.php.net/rfc/howto
If you haven't had experience with writing RFCs before, it is advised to seek guidance on the Internals list (http://php.net/mailing-lists.php) and/or solicit help from one of the experienced developers.
Please to not consider this comment as a negative view on the merits of your proposal - every proposal which requires changes of certain magnitude, even the very successful and widely supported ones, must be done through the RFC process. This helps make the process predictable, transparent and accessible to all developers.