Bug #81573 [Fbk->Csd]: Invalid fatal error regarding mixed return type compatibility
| From: | nikic@php.net | Date: | Thu, 04 Nov 2021 10:03:21 +0000 |
| Subject: | Bug #81573 [Fbk->Csd]: Invalid fatal error regarding mixed return type compatibility | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237543@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
Updated by: nikic@php.net
Reported by: azjezz at protonmail dot com
Summary: Invalid fatal error regarding mixed return type
compatibility
-Status: Feedback
+Status: Closed
Type: Bug
Package: *General Issues
Operating System: N/A
PHP Version: 7.4.25
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Right, this is already fixed. Relevant code is https://github.com/php/php-src/blob/c49cb4c3a780e28cbf3dbfdc8fbc7a615b425635/Zend/zend_inheritance.c#L557-L562.
Previous Comments:
------------------------------------------------------------------------
[2021-11-04 10:00:50] me at kelunik dot com
This has been fixed in PHP 8.0.7 and up already: https://3v4l.org/Uc6TM
------------------------------------------------------------------------
[2021-10-30 18:35:00] 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 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