Bug #70706 [Opn->Nab]: Doesn't evaluate 0

From: Date: Tue, 13 Oct 2015 04:26:07 +0000
Subject: Bug #70706 [Opn->Nab]: Doesn't evaluate 0
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196589@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70706&edit=1 ID: 70706 Updated by: requinix@php.net Reported by: raquilesc at gmail dot com Summary: Doesn't evaluate 0 -Status: Open +Status: Not a bug Type: Bug -Package: *General Issues +Package: Scripting Engine problem Operating System: Linux PHP Version: 5.5.30 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php http://php.net/manual/en/control-structures.switch.php switch (X) { case Y: } is equivalent to if (X == Y) { thus your switch ($a) { case ($a <= 69): } is equivalent to if ($a == ($a <= 69)) { Try switch (true) instead. Previous Comments: ------------------------------------------------------------------------ [2015-10-13 04:16:39] raquilesc at gmail dot com Description: ------------ This code fails, 0 gets ignored and is catch by the 2nd case instead of the first one. Basically indicating than 0 is greater that 69. To evaluate a lower value you need to set it up to 1. $a = 0; switch ($a){ case ($a <= 69) : echo "Less than or equal 69"; break; case ($a > 69 && $a < 80) : echo "greater than 69" ; break; case ($a >= 80) : echo "greater or equal 80" ; break; } Test script: --------------- This code fails, 0 gets ignored and is catch by the 2nd case instead of the first one. Basically indicating than 0 is greater that 69. To evaluate a lower value you need to set it up to 1. $a = 0; switch ($a){ case ($a <= 69) : echo "Less than or equal 69"; break; case ($a > 69 && $a < 80) : echo "greater than 69" ; break; case ($a >= 80) : echo "greater or equal 80" ; break; } Expected result: ---------------- It should evaluate 0 as a value and it is not. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70706&edit=1

« previous php.bugs (#196589) next »