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

From: Date: Thu, 14 Jan 2021 09:04:59 +0000
Subject: Bug #80596 [Ver->Csd]: Invalid union type TypeError in anonymous classes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231555@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: nikic@php.net Reported by: daniil at daniil dot it Summary: Invalid union type TypeError in anonymous classes -Status: Verified +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: Arch linux PHP Version: 8.0.0 Block user comment: N Private report: N New Comment: Automatic comment on behalf of daniil@daniil.it Revision: http://git.php.net/?p=php-src.git;a=commit;h=f9fbba41b66e0e9ccd40ff064d00cfe987c2c5bb Log: Fixed bug #80596: Fix anonymous class union typehint errors Previous Comments: ------------------------------------------------------------------------ [2021-01-13 14:13:29] cmb@php.net 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 ------------------------------------------------------------------------ [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 (#231555) next »