php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71978 Existence of return type hint affects other compatibility rules
Submitted: 2016-04-06 13:56 UTC Modified: 2016-04-06 13:56 UTC
From: dmitry@php.net Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0Git-2016-04-06 (Git) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dmitry@php.net
New email:
PHP Version: OS:

 

 [2016-04-06 13:56 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-06 13:56 UTC] dmitry@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2016-04-06 14:20 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e9d65160e85fb08d9bd08202b60a8b19b446c646
Log: Fixed bug #71978 (Existence of return type hint affects other compatibility rules)
 [2016-04-06 14:20 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 [2016-07-20 11:32 UTC] davey@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e9d65160e85fb08d9bd08202b60a8b19b446c646
Log: Fixed bug #71978 (Existence of return type hint affects other compatibility rules)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 11:01:32 2024 UTC