|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 02:00:01 2025 UTC |
> 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.