note 34194 added to language.oop.object-comparison-php5
| From: | hobbit at euthanized dot org | Date: | Fri, 18 Jul 2003 01:12:50 +0000 |
| Subject: | note 34194 added to language.oop.object-comparison-php5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52308@lists.php.net to get a copy of this message | ||
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.)
----
Manual Page -- http://www.php.net/manual/en/language.oop.object-comparison-php5.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34194
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34194&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34194&report=yes