|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-10-15 21:48 UTC] Wes dot example at example dot org
[2017-10-15 21:55 UTC] stas@php.net
-Package: PHP Language Specification
+Package: *General Issues
[2017-10-16 09:22 UTC] cmb@php.net
-Summary: Fatal error after overriding method and returning
subclass of what parent do
+Summary: PH does not allow covariant return types
-Type: Bug
+Type: Documentation Problem
-Package: *General Issues
+Package: Scripting Engine problem
[2017-10-16 09:22 UTC] cmb@php.net
[2017-10-16 09:23 UTC] cmb@php.net
-Summary: PH does not allow covariant return types
+Summary: PHP does not support covariant return types
[2020-02-16 17:39 UTC] carusogabriel@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: carusogabriel
[2020-02-16 17:39 UTC] carusogabriel@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 17:00:01 2025 UTC |
Description: ------------ Having script like that <?php class ModelBase {} class ModelChild extends ModelBase {} class A { public function test(): ModelBase {} } class B extends A { public function test(): ModelChild {} } ordinary php file.php throws PHP Fatal error: Declaration of B::test(): ModelChild must be compatible with A::test(): ModelBase in file.php on line 13 PHP 7.2.0RC3 (cli) (built: Sep 28 2017 16:28:37) ( NTS ) Copyright (c) 1997-2017 The PHP Group Test script: --------------- <?php class ModelBase {} class ModelChild extends ModelBase {} class A { public function test(): ModelBase {} } class B extends A { public function test(): ModelChild {} } Expected result: ---------------- As ModelChild extends ModelBase, methods expected to return ModelBase should be allowed to be overriden and return its subclass (ModelChild) as it is allowed in any other language that follows OOP principles. Actual result: -------------- PHP Fatal error: Declaration of B::test(): ModelChild must be compatible with A::test(): ModelBase in file.php on line 13