note 34194 deleted from language.oop.object-comparison-php5 by sniper
| From: | sniper@php.net | Date: | Sun, 11 Jan 2004 14:43:50 +0000 |
| Subject: | note 34194 deleted from language.oop.object-comparison-php5 by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63314@lists.php.net to get a copy of this message | ||
Note Submitter: hobbit@euthanized.org
----
Interestingly thing I found PHP5's interface support...
Let me set up the example:
You have an interface called IPrintable
You have a class called A that implements IPrintable
You have a class called B that is derived from A
You have a function called PrintObject (IPrintable $obj)
So the question is do you have to explicitly say that B implements IPrintable in order to pass
objects of class B to PrintObject? Or is the interface implementation implied by the fact that its
parent class implements the interface?
The answer is that it is implied by the fact that A implemented the interface (which is safe to do
and makes sense.) So you do not *have* to explicitly state that B implements the interface in order
to pass objects of class B to PrintObject.
What's interesting though is that you *CAN* explicitly say that B implements the interface and
not actually implement the interface in B...and PHP will accept it because A implements the
interface.
If you do actually implement the interface and implement new functions for B...PHP will use the
functions in B for an object of type B (only climbs as high as it needs to up the object hierchy to
find a given method/methods.)