note 127887 added to control-structures.switch

From: Date: Tue, 01 Nov 2022 16:53:41 +0000
Subject: note 127887 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-219841@lists.php.net to get a copy of this message
Although noted elsewhere, still worth noting is how loose comparison in switch-case was also affected by the change in string to number comparison. Prior PHP8, strings were converted to int before comparison. The reverse is now true which can cause issues for logic that relied on this behavior. <?php function testSwitch($key) { switch ($key) { case 'non numeric string': echo $key . ' matches "non numeric string"'; break; } } testSwitch(0); // pre-PHP8, returns '0 matches "non numeric string"' ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.159.161 (proxied: 139.162.50.236) ---- Manual Page -- https://php.net/manual/en/control-structures.switch.php Edit -- https://main.php.net/note/edit/127887 Del: integrated -- https://main.php.net/note/delete/127887/integrated Del: useless -- https://main.php.net/note/delete/127887/useless Del: bad code -- https://main.php.net/note/delete/127887/bad+code Del: spam -- https://main.php.net/note/delete/127887/spam Del: non-english -- https://main.php.net/note/delete/127887/non-english Del: in docs -- https://main.php.net/note/delete/127887/in+docs Del: other reasons-- https://main.php.net/note/delete/127887 Reject -- https://main.php.net/note/reject/127887 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#219841) next »