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
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: 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: Sun Dec 22 01:01:30 2024 UTC