Bug #81573 [Com]: Invalid fatal error regarding mixed return type compatibility
| From: | hanskrentel at yahoo dot de | Date: | Sat, 30 Oct 2021 18:35:00 +0000 |
| Subject: | Bug #81573 [Com]: Invalid fatal error regarding mixed return type compatibility | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237438@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81573&edit=1
ID: 81573
Comment by: hanskrentel at yahoo dot de
Reported by: azjezz at protonmail dot com
Summary: Invalid fatal error regarding mixed return type
compatibility
Status: Open
Type: Bug
Package: Compile Failure
Operating System: N/A
PHP Version: 7.4.25
Block user comment: N
Private report: N
New Comment:
> 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.
Previous Comments:
------------------------------------------------------------------------
[2021-10-30 16:02:33] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81573&edit=1