|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-11-13 04:16 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
-Package: PHP Language Specification
+Package: *General Issues
[2019-11-13 04:16 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 22:00:01 2025 UTC |
Description: ------------ Not sure if this is a bug or a feature request, but the example code I have posted produces a warning: Warning: Declaration of SubA::fn(SubB $b) should be compatible with A::fn(B $b) SubB is a subclass of B, so the method override in class SubA should be valid. I would expect the behaviour to be similar to how instanceof works: var_dump((new SubB()) instanceof B); //true That line of code returns true, and it should, because of OOP. I understand that warnings are not errors, but when I'm publishing modules which may be used by the general public it is impractical to tell them that they must disable warnings. Is it possible for PHP to respect subclasses in typed method signatures, or will this have unforeseen behaviours I haven't anticipated? Thank you. Test script: --------------- <?php class A { public function fn(B $b) {} } class SubA extends A { public function fn(SubB $b) { parent::fn($b); } } class B {} class SubB extends B {} $obj = new SubA(); $obj->fn(new SubB());