RE: [php-objects] Object comparison in php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Rob,

seems like PHP is comparing the values:

<?php
class Tst {
}

$obj1 = new Tst();
$obj2 = $obj1;
$obj1->a = "a";
$obj2->a = "a";
echo "Test 1: " . ($obj1 == $obj2 ? 'equal' : 'not equal') . "\n";

$obj1->a = "a";
$obj2->a = "b";
echo "Test 2: " . ($obj1 == $obj2 ? 'equal' : 'not equal') . "\n";

$obj1 = & new Tst();
$obj2 = & $obj1;
echo "Test 3: " . ($obj1 == $obj2 ? 'equal' : 'not equal') . "\n";
?>

Output (with PHP 4.2.3):
Test 1: equal
Test 2: not equal
Test 3: equal


> -----Original Message-----
> From: Rob [mailto:rcherry@jamwarehouse.com]
> Sent: Thursday, January 16, 2003 11:14 AM
> To: phpobj
> Subject: [php-objects] Object comparison in php
> 
> 
> If I have two object in php, how does the == operator work?
> 
> E.g. 
> 
> $obj1 = new Object();
> $obj2 = $obj1
> 
> what is the result of ($obj1 == $obj2)?
> 
> What about this?
> 
> $obj1 = & new Object();
> $obj2 = & $obj1
> 
> what is the result of ($obj1 == $obj2)?
> 
> Does the == operator do a memory location comparison for objects, or does
> it actually comare the values within the object?
> 


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Turn flat surfaces into speakers with the Soundbug.
http://us.click.yahoo.com/QWAVSC/onCFAA/xGHJAA/saFolB/TM
---------------------------------------------------------------------~->

Look here for Free PHP Classes of objects:
http://phpclasses.UpperDesign.com/
To unsubscribe from this group, send an email to:
php-objects-unsubscribe@egroups.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux