Bug #73985 [NEW]: Return type of the child may not match the parent

From: Date: Tue, 24 Jan 2017 12:54:50 +0000
Subject: Bug #73985 [NEW]: Return type of the child may not match the parent
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206915@lists.php.net to get a copy of this message
From: david at grudl dot com Operating system: PHP version: 7.1.1 Package: Class/Object related Bug Type: Bug Bug description:Return type of the child may not match the parent Description: ------------ Return type of the child must match the parent: This code leads to "Fatal error: Declaration of B::test(): string must be compatible with A::test(): int" <?php class A { function test(): int {} } class B extends A { function test(): string {} } ?> But it's okay, if I add interface: <?php interface I { function test(); } class A implements I { function test(): int {} } class B extends A { function test(): string {} } ?> Expected result: ---------------- Fatal error: Declaration of B::test(): string must be compatible with A::test(): int Actual result: -------------- no error -- Edit bug report at https://bugs.php.net/bug.php?id=73985&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73985&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73985&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73985&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73985&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73985&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73985&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73985&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73985&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73985&r=support Expected behavior: https://bugs.php.net/fix.php?id=73985&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73985&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73985&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73985&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73985&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73985&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73985&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73985&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73985&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73985&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73985&r=mysqlcfg

« previous php.bugs (#206915) next »