#47499 [Opn->Bgs]: Buggy control flow when switching on 0 (zero)

From: Date: Wed, 25 Feb 2009 01:00:46 +0000
Subject: #47499 [Opn->Bgs]: Buggy control flow when switching on 0 (zero)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-134180@lists.php.net to get a copy of this message
ID: 47499 User updated by: mpb dot mail at gmail dot com Reported By: mpb dot mail at gmail dot com -Status: Open +Status: Bogus Bug Type: Unknown/Other Function Operating System: Linux PHP Version: 5.2.8 New Comment: Ah. You are right. PHP is a crazy language. Previous Comments: ------------------------------------------------------------------------ [2009-02-25 00:56:48] crrodriguez at opensuse dot org $x is an integer, and 'foo' is a string in the first case..which gets casted to an integer so it can be compared... it is the expected behavior... ------------------------------------------------------------------------ [2009-02-25 00:16:12] mpb dot mail at gmail dot com Description: ------------ When switching on 0 (zero), control flow executes the wrong case. Reproduce code: --------------- <?php $x = 0; switch ($x) { case 'foo': print "foo == $x ?\n"; break; case 0: print "0 == $x ?\n"; break; default: print "default: \$x == $x ?\n"; break; } ?> Expected result: ---------------- 0 == 0 ? Actual result: -------------- foo == 0 ? ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47499&edit=1

« previous php.bugs (#134180) next »