Bug #77566 [Opn->Nab]: void type is not covariant to mixed
| From: | cmb@php.net | Date: | Thu, 07 Oct 2021 12:00:11 +0000 |
| Subject: | Bug #77566 [Opn->Nab]: void type is not covariant to mixed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237077@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77566&edit=1
ID: 77566
Updated by: cmb@php.net
Reported by: Wes dot nospam at example dot org
Summary: void type is not covariant to mixed
-Status: Open
+Status: Not a bug
Type: Bug
-Package: *General Issues
+Package: Scripting Engine problem
Operating System: Irrelevant
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> void type is not covariant to mixed
Right[1]. However, having no return type declaration is not the same as
specifying mixed. And the documentation states[2]:
| When overriding a parent method, the child's method must match
| any return type declaration on the parent. If the parent doesn't
| define a return type, then the child method may do so.
So, this is a deliberate design decision, mostly for compatibility
reasons.
[1] <https://3v4l.org/vNF6M>
[2] <https://www.php.net/manual/en/language.types.declarations.php>
Previous Comments:
------------------------------------------------------------------------
[2019-02-04 14:27:22] Wes dot nospam at example dot org
Description:
------------
Going from "has a return value" to "no return value" is certainly not a valid
covariant substitution (at least in theory, in practice void is null).
The void RFC doesn't cover the case at all.
https://wiki.php.net/rfc/void_return_type
It is not unlikely that this is currently allowed by accident.
Thank you.
Test script:
---------------
<?php
class Foo
{
public function aaa(){}
}
class Bar extends Foo
{
public function aaa(): void{}
}
Expected result:
----------------
Error
Actual result:
--------------
No error
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77566&edit=1