Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31330 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86161 invoked by uid 1010); 30 Jul 2007 19:48:26 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 86138 invoked from network); 30 Jul 2007 19:48:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jul 2007 19:48:26 -0000 Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:59017] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/AA-26552-7804EA64 for ; Mon, 30 Jul 2007 15:48:24 -0400 Received: from dhcp-172-30-11-223.zrh.corp.google.com (unknown [216.239.55.7]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id DE6A91B3524; Mon, 30 Jul 2007 21:48:20 +0200 (CEST) Date: Mon, 30 Jul 2007 21:48:20 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <874503525.20070730214820@marcus-boerger.de> To: "Bruno Lustosa" CC: internals@lists.php.net In-Reply-To: References: <468519DC.8060502@widescreen.ch> <4685785E.5010709@zend.com> <585221804.20070701154538@marcus-boerger.de> <1259100072.20070730203433@marcus-boerger.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] toString() and Object #ID From: helly@php.net (Marcus Boerger) Hello Bruno, the documentation says array_diff() uses explicit string casting. Maybe it is time to fix this to object comparision. But then what about mixed arrays? In my opinion it was broken before and you just got lucky with using a debug feature without even knowing. Now the current PHP version at least offers you to do it correctly. Speaking of the mentioned PEAR issue. Now what is your string representation there? Was it actually correct? Was it intended that you were simply comparing class name and handle? Or were you actually expecting to compare the data? Honestly i would expect to compare by elements, say you fetch from a person database into two arrays that are modified differently using php code. Now i'd like to do the test based on the elements, say the ones from the persons.name column. And it does not matter what the different object IDs are....becasue two fetch operations would result in two different IDs even if theay are referring to the same data row. So in this case you apperently do not want to use array_diff() at all. You want to use array_udiff_*(). In the end object to string conversion other than something that leads to a text that can be used on a html or txt file pretty much sounds like a design flaw. marcus Monday, July 30, 2007, 9:30:12 PM, you wrote: > On 7/30/07, Marcus Boerger 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 > ZCE - Zend Certified Engineer - PHP! > http://www.lustosa.net/ Best regards, Marcus