php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15103 object without any data members equals to false
Submitted: 2002-01-18 11:25 UTC Modified: 2002-01-18 11:42 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: phpclub at digiways dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.1.1 OS: any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phpclub at digiways dot com
New email:
PHP Version: OS:

 

 [2002-01-18 11:25 UTC] phpclub at digiways dot com
The code
<?
class A { function foo() {} }
$a = new A;
var_dump($a);
if ($a == false) echo "hahaha";
?>

outputs
"object(a)(0) { } hahaha"

So, for some strange reason PHP thinks that object without data members is "false". Of course, if we replace "==" with "===", it all works fine, but that is still a bug.

This problem exists in all existing PHP versions on all platforms.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-18 11:42 UTC] hholzgra@php.net
the same is true for empty arrays,
"$something == false" is equivalent to
"empty($something)"
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC