Edit report at http://bugs.php.net/bug.php?id=54652&edit=1
ID: 54652 Updated by: pierr...@php.net Reported by: rdli dot data at gmail dot com Summary: Bug when switch expression is zero -Status: Open +Status: Bogus Type: Bug Package: Unknown/Other Function PHP Version: 5.3SVN-2011-05-02 (SVN) Block user comment: N Private report: N New Comment: You need to replace switch($price) by switch(true) so that the first case with an expression evaluated to true will be executed. http://fr.php.net/manual/en/control-structures.switch.php Previous Comments: ------------------------------------------------------------------------ [2011-05-02 23:06:22] felipecg00 at gmail dot com ($price > 100) is false. false is 0, then case is executed. ------------------------------------------------------------------------ [2011-05-02 22:54:12] rdli dot data at gmail dot com Description: ------------ //execute function parameter with $price = 0 myPrice(0); Test script: --------------- function myPrice($price = 50 ){ switch ($price) { case ($price > 100) : echo $price, '<br />'; echo "Price is $100 up."; break; case ($price > 50) : echo "Prince is $50 up."; break; case ($price >25): echo "Prince is $25 up."; break; default: echo "Prince is no more then $25."; break; } } Expected result: ---------------- Prince is no more then $25. Actual result: -------------- 0 Price is $100 up. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54652&edit=1