php.net |  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
 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-26 06:42 UTC] joey@php.net
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-2019 The PHP Group
All rights reserved.
Last updated: Sun Aug 18 22:01:26 2019 UTC