Bug #15010: switch() problem: "+" matches "-"

From: Date: Sat, 12 Jan 2002 23:21:29 +0000
Subject: Bug #15010: switch() problem: "+" matches "-"
Groups: php.dev 
Request: Send a blank email to php-dev+get-76821@lists.php.net to get a copy of this message
From: matthew.somerville@trinity.oxford.ac.uk Operating system: RISC OS PHP version: 4.1.0 PHP Bug Type: Variables related Bug description: switch() problem: "+" matches "-" <? $k = "+"; switch($k) { case "-": print "Oh no!"; case "+": print "Correct!"; } ?> outputs "Oh no!". I guess this is because as switch uses ==, + and - are both being automatically converted to the number 0 which then matches? Could switch() perhaps use === instead of == in its comparison? -- Edit bug report at: http://bugs.php.net/?id=15010&edit=1

« previous php.dev (#76821) next »