# == object comparison bug?

- Thread: https://externals.io/message/9603
- Original archive: https://news-web.php.net/php.internals/9603
- Started by Hans Lellelid on 2004-04-28T17:25:35+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #9603 — Hans Lellelid — 2004-04-28T17:25:35+00:00

URL: https://externals.io/message/9603#9603

I'm using PHP5.0.0RC2.  I saw that there was a similar question posted, 
but apparently that issue had already been fixed.


---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";
}


---output----------------------------

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


I don't know why anything is being coverted to an _integer_.  Is this 
intended behavior?  If so, how do I do a PHP4-style object contents 
comparison? Using === doesn't produce any notice, but also means 
something very different of course.

Hans

---

## #9630 — Andi Gutmans — 2004-05-02T15:40:56+00:00

URL: https://externals.io/message/9603#9630 · In reply to: #9603

Thanks for the detailed report. This should be fixed in the latest CVS.

Andi

At 01:25 PM 4/28/2004 -0400, Hans Lellelid wrote:
>I'm using PHP5.0.0RC2.  I saw that there was a similar question posted, 
>but apparently that issue had already been fixed.
>
>
>---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";
>}
>
>
>---output----------------------------
>
>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
>
>
>I don't know why anything is being coverted to an _integer_.  Is this 
>intended behavior?  If so, how do I do a PHP4-style object contents 
>comparison? Using === doesn't produce any notice, but also means something 
>very different of course.
>
>Hans
