note 73447 added to language.oop5.typehinting

From: Date: Fri, 23 Feb 2007 15:28:21 +0000
Subject: note 73447 added to language.oop5.typehinting
Groups: php.notes 
Request: Send a blank email to php-notes+get-123772@lists.php.net to get a copy of this message
In reply to Nicolas I don't think you exactly understand the inheritance principles If you want to do the equals thing in a decent OO way, you would do something like this: class Object { public equals(Object &o) { return this == &o; //perform default equals check, one could arguably say that === is the correct default, but doesnt matter for the example } } class Chair extends Object { } class Table extends Object { } $chair = new Chair(); $table = new Table(); $chair->equals($table); //will print false (zero) This is actually a correct implementation of an equals method. Since you want to take a chair for example and just call equals() on it WITH ANY OBJECT, you should only hint Object, not an implementation, since the whole point of the equals method is to find out whether it is actually the same object :-) I want to be able to pass a table (which implements Object too, so is perfectly allowed as a parameter to equals). Hope this clears it up a bit for you... :-) ---- Server IP: 194.109.193.76 Probable Submitter: 193.172.11.178 (proxied: 1.1 S006) ---- Manual Page -- http://www.php.net/manual/en/language.oop5.typehinting.php Edit -- https://master.php.net/note/edit/73447 Del: integrated -- https://master.php.net/note/delete/73447/integrated Del: useless -- https://master.php.net/note/delete/73447/useless Del: bad code -- https://master.php.net/note/delete/73447/bad+code Del: spam -- https://master.php.net/note/delete/73447/spam Del: non-english -- https://master.php.net/note/delete/73447/non-english Del: in docs -- https://master.php.net/note/delete/73447/in+docs Del: other reasons-- https://master.php.net/note/delete/73447 Reject -- https://master.php.net/note/reject/73447 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123772) next »