note 61097 deleted from control-structures.switch by bjori

From: Date: Fri, 28 Apr 2006 14:23:58 +0000
Subject: note 61097 deleted from control-structures.switch by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-109987@lists.php.net to get a copy of this message
Note Submitter: sanate at seznam dot cz ---- <?php switch ($i) { case 'a': echo "i equals a"; break; case 'b': echo "i equals b"; break; case 'c': echo "i equals c"; break; default: echo "i is not equal to a, b or c"; } ?> Yes, it is true. Be careful if the compared variable === true! Because: IT WILL "convert" any unempty string to true AND it will go directly to the FIST case and print "i equals a" in that example !!! How non-sens-making behavior! At first I thought it is a bug. :) If I could I would definitely change this nonsense-behavior in case of true! (for example by converting it internally to number 1). But I am not requesting it - I know it is not possible here... Just wanted to say: People, Be extra careful not to get true dropped into a switch! :-)

« previous php.notes (#109987) next »