php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81573 Invalid fatal error regarding mixed return type compatibility
Submitted: 2021-10-30 16:02 UTC Modified: 2021-11-04 10:03 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: azjezz at protonmail dot com Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 7.4.25 OS: N/A
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: azjezz at protonmail dot com
New email:
PHP Version: OS:

 

 [2021-10-30 16:02 UTC] azjezz at protonmail dot com
Description:
------------
This bug occurs on PHP 7.4, 8.0, and 8.1-dev.

when the return type of a method is changed in a sub-class from `mixed` to `T` and `T` is undefined, you get a fatal error.

This shouldn't result in any type of error as `T` is a sub-type of `mixed`.

reference: https://github.com/revoltphp/event-loop/pull/15/files

Test script:
---------------
<?php

class A {
    public function foo(): mixed { exit(0); }
}

class B extends A {
    public function foo(): C { exit(0); }
}

Expected result:
----------------
no errors.


Actual result:
--------------
Fatal error: Could not check compatibility between B::foo(): C and A::foo(): mixed, because class C is not available in /in/k7Jmq on line 8

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-30 18:35 UTC] hanskrentel at yahoo dot de
> This bug occurs on PHP 7.4, 8.0, and 8.1-dev.

My understanding it that in PHP 7.4 it triggers the autoloader for mixed.

> This shouldn't result in any type of error as `T` is a sub-type of `mixed`.

Undefined types have never been a sub-type in PHP. Not in PHP 8.1, 8.0 7.4 or any previous version. The introduction of the special type "mixed" in PHP 8.0 has not changed that AFAIK.

Compare with a code that demonstrates what establishes a bug on your end with the less special type stdClass of which any type in PHP userspace is a sub-type of (as we can only defined classes):

<?php

class A {
    public function foo(): stdClass { exit(0); }
}

class B extends A {
    public function foo(): C { exit(0); }
}

Fatal error: Could not check compatibility between B::foo(): C and A::foo(): stdClass, because class C is not available in /in/vsMsS on line 8

The behaviour on mixed looks pretty well aligned in my eyes to the standard behaviour, therefore it would help if you could elaborate why this should be a) different for mixed and b) even qualify as a bug.
 [2021-10-30 19:32 UTC] requinix@php.net
-Status: Open +Status: Feedback -Package: Compile Failure +Package: *General Issues
 [2021-11-04 10:00 UTC] me at kelunik dot com
This has been fixed in PHP 8.0.7 and up already: https://3v4l.org/Uc6TM
 [2021-11-04 10:03 UTC] nikic@php.net
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 00:01:41 2024 UTC