note 27359 deleted from control-structures.switch by peehaa
| From: | peehaa@php.net | Date: | Mon, 02 Dec 2013 09:11:38 +0000 |
| Subject: | note 27359 deleted from control-structures.switch by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197695@lists.php.net to get a copy of this message | ||
Note Submitter: turk162 at ALLSPAM_hotmail dot com
----
On PHP V4.2.1, running on IIS5 as a CGI, I found an anomaly with how SWITCH handled strings.
I've heard that this problem doesn't exist on V4.2.3 on Apache.
This snippet took the wrong branch:
<?PHP
$wonum = '20010E0';
SWITCH ($wonum):
CASE '20010D0';
ECHO "<BR>Branching at D with wonum: " . $wonum;
BREAK;
CASE '20010E0';
ECHO "<BR>Branching at E with wonum: " . $wonum;
BREAK;
ENDSWITCH;
?>
Type casting with $wonum = (STRING) '20010E0'; didn't help.
Changing the order of the CASEs made no difference (it shouldn't, but...)
What did work was using MD5 to force a string comparison:
<?PHP
$wonum = MD5('20010E0');
SWITCH ($wonum):
CASE MD5('20010D0');
ECHO "<BR>Branching at D with wonum: " . $wonum;
BREAK;
CASE MD5('20010E0');
ECHO "<BR>Branching at E with wonum: " . $wonum;
BREAK;
ENDSWITCH;
?>
Moral: test test test