note 61097 added to control-structures.switch

From: Date: Wed, 25 Jan 2006 17:24:33 +0000
Subject: note 61097 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-102431@lists.php.net to get a copy of this message
<?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! :-) ---- Server IP: 212.24.129.6 Probable Submitter: 86.49.29.244 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61097 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61097&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61097&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61097&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61097&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61097&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61097&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61097&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61097&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102431) next »