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

From: Date: Wed, 06 Jan 2021 12:16:17 +0000
Subject: Bug #80596 [NEW]: Invalid union type TypeError in anonymous classes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231390@lists.php.net to get a copy of this message
From: daniil at daniil dot it Operating system: Arch linux PHP version: 8.0.0 Package: Scripting Engine problem Bug Type: Bug Bug description:Invalid union type TypeError in anonymous classes 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 bug report at https://bugs.php.net/bug.php?id=80596&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80596&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80596&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80596&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80596&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80596&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80596&r=support Expected behavior: https://bugs.php.net/fix.php?id=80596&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80596&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80596&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80596&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80596&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80596&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80596&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80596&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80596&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80596&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80596&r=mysqlcfg

« previous php.bugs (#231390) next »