Bug #74315 [NEW]: Fatal error: Declaration of test2::test() must be compatible with test1::test()

From: Date: Sun, 26 Mar 2017 07:02:30 +0000
Subject: Bug #74315 [NEW]: Fatal error: Declaration of test2::test() must be compatible with test1::test()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208080@lists.php.net to get a copy of this message
From: spam2 at rhsoft dot net Operating system: Linux PHP version: 7.1.3 Package: Scripting Engine problem Bug Type: Bug Bug description:Fatal error: Declaration of test2::test() must be compatible with test1::test() Description: ------------ it's annoying enough at all that you get warnings when method declarations are not 100% identical in case of adding param-type-hints in the underlying classes without change all extended classes at the same time but in case of return types a fatal error is just unacceptable (and no it also don't make sense that you can't skip optional params in a extended class or add additional ones to change the behavior of the parent-call) ________________________________ unacceptable because you can't add them at all without hard breaking every dervied code while in case of the annoying warnings you can at least adopt the changes while watching errorlog and sites ar enot completly broken [harry@srv-rhsoft:/downloads]$ php test.php Fatal error: Declaration of test2::test() must be compatible with test1::test(): array in /mnt/data/downloads/test.php on line 2 Test script: --------------- [harry@srv-rhsoft:/downloads]$ cat test.php <?php class test2 extends test1 { public function test() { } } class test1 { public function test(): array { } } ?> Expected result: ---------------- no error and in the best case even no warning at all, extedning a class and override methods in doubt always imply changed behavior with or without changing method signatures Actual result: -------------- Fatal error: Declaration of test2::test() must be compatible with test1::test(): array in /mnt/data/downloads/test.php on line 2 -- Edit bug report at https://bugs.php.net/bug.php?id=74315&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74315&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74315&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74315&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74315&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74315&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74315&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74315&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74315&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74315&r=support Expected behavior: https://bugs.php.net/fix.php?id=74315&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74315&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74315&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74315&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74315&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74315&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74315&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74315&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74315&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74315&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74315&r=mysqlcfg

« previous php.bugs (#208080) next »