note 73447 deleted from language.oop5.typehinting by cmb
| From: | cmb@php.net | Date: | Sat, 10 Dec 2016 11:52:08 +0000 |
| Subject: | note 73447 deleted from language.oop5.typehinting by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208443@lists.php.net to get a copy of this message | ||
Note Submitter: Nikivich
----
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... :-)