php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77562 Inheritance signature checking for void return type
Submitted: 2019-02-04 06:50 UTC Modified: 2019-02-04 08:11 UTC
From: danack@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.2.14 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: danack@php.net
New email:
PHP Version: OS:

 

 [2019-02-04 06:50 UTC] danack@php.net
Description:
------------
From PHP 7.2 dropping the return type for methods in child classes is meant to be allowed on method signature checks: https://wiki.php.net/rfc/parameter-no-type-variance


Test script:
---------------
class Foo{
    function method (): void  {}
}
 
// This should work in php 7.2+
class Bar extends Foo {
    function method () {} 
}



Expected result:
----------------
No error.

Actual result:
--------------
Fatal error: Declaration of Bar::method() must be compatible with Foo::method(): void in /in/3E70o on line 11

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-04 08:11 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2019-02-04 08:11 UTC] nikic@php.net
Dropping the *parameter* types is allowed, not the return types. Dropping parameter types is legal because parameters are contravariant. Dropping return types would violate LSP, because they are covariant.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC