toString() and Object #ID
| From: | Bruno Lustosa | Date: | Mon, 30 Jul 2007 19:30:12 +0000 |
| Subject: | toString() and Object #ID | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-31329@lists.php.net to get a copy of this message | ||
On 7/30/07, Marcus Boerger <helly@php.net> wrote:
> Hello Pavel,
>
> I still fail to understand why spl_object_hash() does not work for you.
Hello.
Just as a side note, this broke a few things for me. For example, in
an application, I have 2 arrays of objects, and I try to call
array_diff() on them.
Before PHP 5.2, it would work, possibly because array_diff() would
cast the objects as strings, and then compare them (if I understood
the problem correctly).
Now, this doesn't work anymore, because the object can't be cast to
string by default.
Of course, I could add a __toString() method to the objects and return
something there, but problem is, all objects are extended from a base
class from PEAR (it's DB_DataObject), and it wouldn't be a Good Thing
to modify the PEAR class directly (updates would break).
So, I got kind of stuck, and tried to add the __toString() dynamically
to the objects in question using the "runkit" PECL package, but
although it adds the method correctly, PHP doesn't recognize it as a
magic method, and won't call it when needed (filed bug #11691 on PECL
for it).
Do you think there's an easy and clean approaching to solve this kind
of problem? Or maybe the problem should be solved on array_diff() and
other functions to make them not try to cast the object as a string to
compare?
Thanks
--
Bruno Lustosa <bruno@lustosa.net>
ZCE - Zend Certified Engineer - PHP!
http://www.lustosa.net/