|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-04-08 21:32 UTC] requinix@php.net
-Status: Open
+Status: Duplicate
-Package: PHP Language Specification
+Package: *General Issues
[2017-04-08 21:32 UTC] requinix@php.net
[2017-04-08 22:15 UTC] spam2 at rhsoft dot net
[2017-04-08 23:17 UTC] requinix@php.net
[2017-04-08 23:41 UTC] spam2 at rhsoft dot net
[2017-04-09 00:14 UTC] nikic@php.net
[2017-04-09 00:53 UTC] spam2 at rhsoft dot net
[2017-04-09 00:59 UTC] spam2 at rhsoft dot net
[2017-04-09 16:34 UTC] spam2 at rhsoft dot net
[2017-11-20 13:40 UTC] spam2 at rhsoft dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 09:00:02 2025 UTC |
Description: ------------ Warning: Declaration of B::test(string $a) should be compatible with A::test($a) Fatal error: Declaration of B::test($a) must be compatible with A::test($a): string in /mnt/data/downloads/test.php on line 17 ___________________________________________ case 1: Warning - that can be handeled <?php declare(strict_types=1); class A { public function test($a) { } } class B extends A { public function test(string $a) { } } ?> ___________________________________________ case 2: introduce a return type in the extended class is even possible <?php declare(strict_types=1); $x = new B(); class A { public function test($a) { } } class B extends A { public function test($a): string { } } ?> ___________________________________________ case 3: add return types in the base class breaks any code which extends it and that makes it just impossible to introduce return-types on a larger code base becaus eyou would need to *first* add the return types to every extended class and only after that is done you can add it to the shared library providing the base class - in case of scalar type-hints you just need to "tail -f" on the error logs and fix the warnings while all sites are online and working <?php declare(strict_types=1); $x = new B(); class A { public function test($a): string { } } class B extends A { public function test($a) { } } ?> Expected result: ---------------- only a warning when the base class defines a return type and the extend class not to have a way fix the dfinitions in all code wich extends the base class while the pages ar enot broken Actual result: -------------- impossible to introduce return types on classes which are extended without touch *before* any extending code - that is not realistic in case of hundrets of virtual hosts and more important makes it impossible for anybody who publishes php-classes to add return-types without completly break users code