Bug #71978 [Opn->Asn]: Existence of return type hint affects other compatibility rules

From: Date: Wed, 06 Apr 2016 13:56:56 +0000
Subject: Bug #71978 [Opn->Asn]: Existence of return type hint affects other compatibility rules
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200402@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71978&edit=1 ID: 71978 Updated by: dmitry@php.net Reported by: dmitry@php.net Summary: Existence of return type hint affects other compatibility rules -Status: Open +Status: Assigned Type: Bug Package: Scripting Engine problem Operating System: * PHP Version: 7.0Git-2016-04-06 (Git) -Assigned To: +Assigned To: dmitry Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2016-04-06 13:56:37] dmitry@php.net Description: ------------ Children classes may override methods with different argument types. This leads to Warning. However if the same methods in addition have the same return type PHP emits "Fatal Error" instead of "Warning" Test script: --------------- <?php class A { function foo(int $a) {} } class B extends A { function foo(string $a) {} } class A1 { function foo(int $a): int {} } class B1 extends A1 { function foo(string $a): int {} } ?> Expected result: ---------------- Warning: Declaration of B::foo(string $a) should be compatible with A::foo(int $a) in %s on line %d Warning: Declaration of B1::foo(string $a): int should be compatible with A1::foo(int $a): int in %s on line %d Actual result: -------------- Warning: Declaration of B::foo(string $a) should be compatible with A::foo(int $a) in %s on line %d Fatal Error: Declaration of B1::foo(string $a): int must be compatible with A1::foo(int $a): int in %s on line %d ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71978&edit=1

« previous php.bugs (#200402) next »