note 85578 added to language.oop5.object-comparison

From: Date: Sat, 06 Sep 2008 21:02:39 +0000
Subject: note 85578 added to language.oop5.object-comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-144202@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 67.150.169.66 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.object-comparison.php Edit -- https://master.php.net/note/edit/85578 Del: integrated -- https://master.php.net/note/delete/85578/integrated Del: useless -- https://master.php.net/note/delete/85578/useless Del: bad code -- https://master.php.net/note/delete/85578/bad+code Del: spam -- https://master.php.net/note/delete/85578/spam Del: non-english -- https://master.php.net/note/delete/85578/non-english Del: in docs -- https://master.php.net/note/delete/85578/in+docs Del: other reasons-- https://master.php.net/note/delete/85578 Reject -- https://master.php.net/note/reject/85578 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144202) next »