php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6719 Default argument values not working correctly when 0 is passed as a value
Submitted: 2000-09-13 17:51 UTC Modified: 2000-09-13 17:57 UTC
From: sasha at spuni dot is Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0.2 OS: Linux RedHat 6.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sasha at spuni dot is
New email:
PHP Version: OS:

 

 [2000-09-13 17:51 UTC] sasha at spuni dot 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!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-13 17:57 UTC] sniper@php.net
Change this line:

if ($p == "all" )

to 

if ($p === "all" )

and you get desired behaviour.

--Jani
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 01 03:01:28 2024 UTC