Page 1 of 1

Comparing objects instances

Posted: Sat Mar 25, 2006 1:57 am
by alex.barylski
I need to compare two objects, but using the === operator won't work...

Partly because, from what I can tell, PHP object comparison works like:

1) Both objects have the exact same attributes and values
2) Both objects are of the same class

Using the === operator would yield TRUE but I have an instance where more than one object may very well have the same type, attributes and values...

So what I need then is access to an objects instance handle...

Doesn't look like PHP supports this???

I have a work around already figured out, soooo all I want to know is, does PHP have native access to an object instance handle?

Does every object in PHP have a magic property or something that give that instance total uniqueness???

Anyone know of anything like that/this in PHP4???

Cheers :)

Posted: Sat Mar 25, 2006 2:01 am
by feyd
take a look at SimpleTest's code. There's a nice set of tools in there that, for one, can detect if x is a reference to y (isReference)

Posted: Sat Mar 25, 2006 2:32 am
by alex.barylski
feyd wrote:take a look at SimpleTest's code. There's a nice set of tools in there that, for one, can detect if x is a reference to y (isReference)
I've looked into SimpleTest before, but perhaps it's time I take a more serious approach :)

Anyways, I've already determined how I would implement unique object instances, but what I really wanted to know is if PHP had native support for it already?

So when I release my code to the public I don't get slammed for being redundant :)

If there is no get_instance() function in PHP natively, I guess I'll use my work around :)