note 85578 deleted from language.oop5.object-comparison by googleguy

From: Date: Tue, 22 Oct 2013 08:02:50 +0000
Subject: note 85578 deleted from language.oop5.object-comparison by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-196762@lists.php.net to get a copy of this message
Note Submitter: wbcarts at juno dot com ---- COMPARISONS AND EQUALITY are NOT the same I'm not sure that the PHP Example #1 above is clear enough. In my own experience, I have found there is a distinct difference between a "comparison" and a "test for equality". The difference is found in the possible return values of the function being used, for example. /* * Test two values for EQUALITY - returns (boolean) TRUE or FALSE. */ function equals($a, $b) { return ($a == $b); } /* * COMPARE two values - returns (int) -1, 0, or 1. */ function compare($a, $b) { if($a < $b) return -1; else if($a == $b) return 0; else if($a > $b) return 1; else return -1; } My examples clarify the difference between "making a comparison" and "testing for equality". You can substitute any of the "==" with "===" for example, but the point is on the possible return values of the function. All tests for EQUALITY will return TRUE or FALSE, and a COMPARISON will give a "<", "==", or ">" answers... which you can then use for sorting.

« previous php.notes (#196762) next »