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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 06:01:34 2025 UTC