Bug #77562 [Opn->Nab]: Inheritance signature checking for void return type
| From: | nikic@php.net | Date: | Mon, 04 Feb 2019 08:11:16 +0000 |
| Subject: | Bug #77562 [Opn->Nab]: Inheritance signature checking for void return type | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219354@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77562&edit=1
ID: 77562
Updated by: nikic@php.net
Reported by: danack@php.net
Summary: Inheritance signature checking for void return type
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.2.14
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2019-02-04 06:50:20] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77562&edit=1