note 58623 added to language.oop5.typehinting

From: Date: Thu, 10 Nov 2005 02:44:05 +0000
Subject: note 58623 added to language.oop5.typehinting
Groups: php.notes 
Request: Send a blank email to php-notes+get-98353@lists.php.net to get a copy of this message
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.*/ ?> ---- Manual Page -- http://www.php.net/manual/en/language.oop5.typehinting.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58623 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58623&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58623&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58623&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58623&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58623&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58623&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58623&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58623&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#98353) next »