PHP 4.0 Bug #6719 Updated: Default argument values not working correctly when 0 is passed as a value

From: Date: Wed, 13 Sep 2000 21:57:05 +0000
Subject: PHP 4.0 Bug #6719 Updated: Default argument values not working correctly when 0 is passed as a value
Groups: php.dev 
Request: Send a blank email to php-dev+get-33152@lists.php.net to get a copy of this message
ID: 6719 Updated by: sniper Reported By: sasha@spuni.is Status: Closed Bug Type: *General Issues Assigned To: Comments: Change this line: if ($p == "all" ) to if ($p === "all" ) and you get desired behaviour. --Jani Previous Comments: --------------------------------------------------------------------------- [2000-09-13 17:51:20] sasha@spuni.is <? function f($p = "all") { if ($p == "all") { print "if condition true, p = $p"; } else { print "if condition false, p = $p"; } print "<br>"; } f(); f(0); f(1); ?> The output of this script is: if condition true, p = all if condition true, p = 0 if condition false, p = 1 and the problem is actually in second row generated by function call f(0). In this case $p is 0 but the condition $p == "all" is true! --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=6719

« previous php.dev (#33152) next »