php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28219 == object comparison produces E_NOTICE
Submitted: 2004-04-29 18:38 UTC Modified: 2004-04-29 20:20 UTC
From: hans at velum dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0RC2 OS: Linux
Private report: No CVE-ID: None
 [2004-04-29 18:38 UTC] hans at velum dot net
Description:
------------
I get 

Notice: Object of class File could not be converted to integer

when trying to compare object contents using '==' comparison operator.  Comparing the actual reference using === works, but obviously means something different.

Reproduce code:
---------------
class File {
    public $var;
    function __construct($val) {
        $this->var = $val;
    }
}

$t1 = new File("test");
$t2 = new File("test");

print_r($t1);
print_r($t2);

print "\$t1 == \$t2 ?";
if ($t1 == $t2) {
    print "YES\n";
} else {
    print "NO\n";
} 

Expected result:
----------------
File Object
(
    [var] => test
)
File Object
(
    [var] => test
)
$t1 == $t2 ? YES 

Actual result:
--------------
File Object
(
    [var] => test
)
File Object
(
    [var] => test
)
$t1 == $t2 ?
Notice: Object of class File could not be converted to integer in /var/www/apps/ddi/test.php on line 18

Notice: Object of class File could not be converted to integer in /var/www/apps/ddi/test.php on line 18
YES 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-29 20:20 UTC] derick@php.net
Duplicate of bug #28165. Please search the database before filing a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 08:01:33 2024 UTC