Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63791 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45530 invoked from network); 9 Nov 2012 09:51:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Nov 2012 09:51:08 -0000 Authentication-Results: pb1.pair.com header.from=fullmoon@newsguy.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php-php-dev@m.gmane.org; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain m.gmane.org designates 80.91.229.3 as permitted sender) X-PHP-List-Original-Sender: php-php-dev@m.gmane.org X-Host-Fingerprint: 80.91.229.3 plane.gmane.org Received: from [80.91.229.3] ([80.91.229.3:43377] helo=plane.gmane.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 12/11-31177-B02DC905 for ; Fri, 09 Nov 2012 04:51:07 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1TWlF1-0008PL-0J for internals@lists.php.net; Fri, 09 Nov 2012 10:51:11 +0100 Received: from 170.sub-75-228-244.myvzw.com ([75.228.244.170]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 09 Nov 2012 10:51:10 +0100 Received: from fullmoon by 170.sub-75-228-244.myvzw.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 09 Nov 2012 10:51:10 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: internals@lists.php.net Date: Fri, 09 Nov 2012 02:50:51 -0700 Lines: 50 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 170.sub-75-228-244.myvzw.com User-Agent: Mozilla/5.0 (X11; Linux i686; rv:14.0) Gecko/20120714 Thunderbird/14.0 In-Reply-To: X-Archive: encrypt Subject: Re: [PHP-DEV] Object comparison From: fullmoon@newsguy.com (crankypuss) On 11/08/2012 05:07 PM, Sara Golemon wrote: > From: http://php.net/manual/en/language.operators.comparison.php > > An object compared to anything which is not a bool, null, or object > should result in the object appearing to be greater than the other > operand. For example: > > $a = new stdClass(); > $b = new stdClass(); > > var_dump(null < $a); > var_dump(false < $a); > var_dump(true == $a); > var_dump($a == $b); > var_dump(0 < $a); > var_dump(1 < $a); // false > var_dump(2 < $a); // false > var_dump("foo" < $a); > var_dump("2" < $a); > var_dump(tmpfile() < $a); > > Based on docs, I expect all nine of these to yield true, however in > practice, the two marked "false" come out as false because the RHS > object is converted to an integer (1), contrary to the docs. > > Doc bug? Or code bug? I'm inclined to call it a code bug, but wanted > others' thoughts. > > -Sara > You seem to be reporting a bug ("contrary to the docs"), but you might be suggesting that the doc be corrected (since doc and behaviour should always match). I would suggest being very careful about implementing something as central as a change to how comparisons are made, that ought to be approached with great caution because it has the potential for breaking a huge amount of existing code. [It does occur to me however, simply as a point of interest, that objects traditionally have both a constructor and a destructor, and the idea of objects also having a comparator makes a certain amount of sense; a default object comparator might implement the currently defined comparisons while allowing derived classes to override the default behaviour and leaving comparisons not involving objects undisturbed.] Comparing objects to scalars is really an apples/oranges comparision to begin with.