|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7478 empty() function does not work as expected
Submitted: 2000-10-26 05:52 UTC Modified: 2000-10-26 06:42 UTC
From: heiner at bintec dot de Assigned:
Status: Closed Package: Variables related
PHP Version: 4.0.0 OS: Solaris 2.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: heiner at bintec dot de
New email:
PHP Version: OS:


 [2000-10-26 05:52 UTC] heiner at bintec dot de
The following code fragment terminates the script:

    $id = "0";
    if ( empty ($id) ) {
        die ("FATAL: need unique ID number");

I would have expected, that

    empty ("0")

is always FALSE, because a string containing the character "0" is
definitively not empty [I know that empty() expects a variable, not a constant
as argument].

The expression

    if ( empty($var) ) ...

seems to be identical to

    if ( !$var ) ...

I strongly feel that empty() should not consider a string with a "0" content
as empty. This functionality is already covered with "if ( !$var)".

Heiner Steven


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-26 06:42 UTC]
To be more precise, empty() covers the following:
if ( (! isset($var)) && (! $var) )

This is what empty is made to do. You are probably looking
for isset().
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Oct 22 23:03:34 2021 UTC