ID: 42330 User updated by: udo dot rader at bestsolution dot at Reported By: udo dot rader at bestsolution dot at Status: Wont fix Bug Type: Scripting Engine problem Operating System: Linux PHP Version: 5.2.3 New Comment:
Hmm, too bad. The link you provided about the PDM meeting says "that most probably no language currently implements this correctly" is not true. Java for instance does this just nicely at least since 1.3. With that limitation, the implementation of an AbstractDAO/AbstractFactory pattern will fail if type hinting is wanted, because transfer objects need to be identifyable by their common interface. Otherwise the entire interface thing in PHP does not make much sense, IMHO. So anyhow, at least the error message should be changed to be more clear. Previous Comments: ------------------------------------------------------------------------ [2007-08-17 17:47:13] [EMAIL PROTECTED] PHP does not implement inheritance checks for typehinted arguments. Please also refer to the PDM meeting notes, where this was discussed: http://www.php.net/~derick/meeting-notes.html#implement-inheritance-rules-for-type-hints ------------------------------------------------------------------------ [2007-08-17 17:31:48] udo dot rader at bestsolution dot at Description: ------------ When using type hinting with interfaces it fails to recognoize classes implementing the interface as "compatible". Reproduce code: --------------- abstract class Foo { abstract public function saySomething( IBar $what ); abstract public function saySomethingElse( IBar $what ); } class BarDAO extends Foo { function saySomething( IBar $what ) { echo $what->getMessage(); } function saySomethingElse( BarTransfer $what ) { echo $what->getMessage(); } } interface IBar { function getMessage(); } class BarTransfer implements IBar { function getMessage() { return "Hello from BarTransfer"; } } $barDAO = new BarDAO(); $barTransfer = new BarTransfer(); $barDAO->saySomething( $barTransfer ); $barDAO->saySomethingElse( $barTransfer ); Expected result: ---------------- The expected result should be that no compiler error occurs and that the script runs. Actual result: -------------- The PHP interpreter gives this error: Fatal error: Declaration of BarDAO::saySomethingElse() must be compatible with that of Foo::saySomethingElse() But, IMHO, BarTransfer can hardly be more "compatible" with IBar. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42330&edit=1
