|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-06-19 22:21 UTC] helly@php.net
[2012-04-20 10:39 UTC] kabanovdmitry at gmail dot com
[2013-10-14 12:07 UTC] worldoffame at hotmail dot com
[2013-10-14 12:25 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 00:00:02 2025 UTC |
Description: ------------ When adding type hinting to an interface then implementing that interface using a derived class, the script compiler does not seem to recognise that the implemented type hint is derived from the interfaces type hint. I hope that makes sense. The code below may be more clear. Reproduce code: --------------- <?php interface MyInterface{public function test(ClassA $object);} class MyClass implements myInterface{ public function test(ClassB $object){// should work but does not echo $object->x; } } class ClassA {public$x = "Class is ClassA"; } class ClassB extends ClassA{ public $x = "Class is ClassB";} $myclass = new MyClass; $a = new ClassA; $b = new ClassB; $myclass->test($b); $myclass->test($a); ?> Expected result: ---------------- Class is ClassB Fatal error: Argument 1 passed to MyClass::test() must be an instance of ClassB, called in typeHintTest.php on line 14 and defined in typeHintTest.php on line 4 Actual result: -------------- Fatal error: Declaration of MyClass::test() must be compatible with that of MyInterface::test() in typeHintTest.php on line 3