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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC