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
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: 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

Patches

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 13:01:34 2025 UTC