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

Add a Patch

Pull Requests

Add a Pull Request

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 Apr 27 23:01:30 2024 UTC