Bug #80596 [PATCH]: Invalid union type TypeError in anonymous classes

From: Date: Wed, 13 Jan 2021 14:13:29 +0000
Subject: Bug #80596 [PATCH]: Invalid union type TypeError in anonymous classes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231538@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 Patch added by: cmb@php.net Reported by: daniil at daniil dot it Summary: Invalid union type TypeError in anonymous classes 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: The following pull request has been associated: Patch Name: Fix #80596 - broken anonymous class union typehint errors On GitHub: https://github.com/php/php-src/pull/6601 Patch: https://github.com/php/php-src/pull/6601.patch Previous Comments: ------------------------------------------------------------------------ [2021-01-13 09:46:40] daniil at daniil dot it The following patch has been added/updated: Patch Name: fix-anonymous-class-union-typehints Revision: 1610531200 URL: https://bugs.php.net/patch-display.php?bug=80596&patch=fix-anonymous-class-union-typehints&revision=1610531200 ------------------------------------------------------------------------ [2021-01-06 12:20:58] cmb@php.net Confirmed: <https://3v4l.org/e83WV>. ------------------------------------------------------------------------ [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 (#231538) next »