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

From: Date: Wed, 13 Sep 2000 21:51:20 +0000
Subject: PHP 4.0 Bug #6719: 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-33150@lists.php.net to get a copy of this message
From: sasha@spuni.is Operating system: Linux RedHat 6.2 PHP version: 4.0.2 PHP Bug Type: *General Issues Bug description: Default argument values not working correctly when 0 is passed as a value <? 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!

« previous php.dev (#33150) next »