php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77566 void type is not covariant to mixed
Submitted: 2019-02-04 14:27 UTC Modified: 2021-10-07 12:00 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: Wes dot nospam at example dot org Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: Irrelevant
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: Wes dot nospam at example dot org
New email:
PHP Version: OS:

 

 [2019-02-04 14:27 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-07 12:00 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: *General Issues +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2021-10-07 12:00 UTC] cmb@php.net
> 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>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 05:01:27 2024 UTC