Bug #80596 [Opn->Ver]: Invalid union type TypeError in anonymous classes

From: Date: Wed, 06 Jan 2021 12:20:58 +0000
Subject: Bug #80596 [Opn->Ver]: Invalid union type TypeError in anonymous classes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231391@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80596&edit=1 ID: 80596 Updated by: cmb@php.net Reported by: daniil at daniil dot it Summary: Invalid union type TypeError in anonymous classes -Status: Open +Status: Verified Type: Bug Package: Scripting Engine problem Operating System: Arch linux PHP Version: 8.0.0 Block user comment: N Private report: N New Comment: Confirmed: <https://3v4l.org/e83WV>. Previous Comments: ------------------------------------------------------------------------ [2021-01-06 12:16:17] daniil at daniil dot it Description: ------------ Type errors thrown for union typehints containing self in an anonymous class contain only class@anonymous in the error message, without the full typehint. Test script: --------------- class a { public function test(): self|string { return new \stdClass; } }; $b = new class { public function test(): self|string { return new \stdClass; } }; try { (new a)->test(); } catch (\Throwable $e) { echo $e->getMessage().PHP_EOL; } try { $b->test(); } catch (\Throwable $e) { echo $e->getMessage().PHP_EOL; } Expected result: ---------------- a::test(): Return value must be of type a|string, stdClass returned class@anonymous::test(): Return value must be of type class@anonymous|string, stdClass returned Actual result: -------------- a::test(): Return value must be of type a|string, stdClass returned class@anonymous::test(): Return value must be of type class@anonymous, stdClass returned ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80596&edit=1

« previous php.bugs (#231391) next »