note 58623 deleted from language.oop5.typehinting by bjori
| From: | bjori@php.net | Date: | Fri, 14 Apr 2006 14:57:17 +0000 |
| Subject: | note 58623 deleted from language.oop5.typehinting by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-108082@lists.php.net to get a copy of this message | ||
Note Submitter: mail dot phatlip at gmail dot com
----
Thats not a language issure - thats your own logical issue.
Why would you ask for an instance of Testinterface and then try and run a function that does not
exist in Testinterface at all.
for example
<?php
interface Testinterface {
function methodA() {}
}
class class1 impements Testinterface {
function methodA() {
echo 'A';
}
}
function main( Testinterface $foo ) {
$foo->methodA();
}
$bar = new class1();
main( $bar );
/*This makes sense, as the only method in the interface is methodA() - if we want to have 'java
compliant' (why would we want that, we're programming PHP?) code then we want the function
to only execute methods that are included in said interface. IE if you type hint by interface -
don't include methods that don't exist in that interface as this may or may not call an
error depending on the object's class.
Rather, the point of being able to use type hinting with interfaces is so that you KNOW that certain
methods will exist for any objects that you want to manage. It is NOT an attempt to type cast the
passed object.*/
?>