|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81630 PHP 8.1: ReflectionClass->getTraitAliases() crashes with Internal error
Submitted: 2021-11-17 12:55 UTC Modified: 2021-11-17 14:28 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: ondrej at mirtes dot cz Assigned:
Status: Closed Package: Reflection related
PHP Version: 8.1.0RC6 OS: N/A
Private report: No CVE-ID: None
 [2021-11-17 12:55 UTC] ondrej at mirtes dot cz
Unfortunately I don't have a simple reproducing script here, but I know there's a bug in ReflectionClass when asking for trait aliases.

A code that executes the same methods crashes when I run it in context of PHPStan:

The error message is:

Uncaught Error: Internal error: Failed to retrieve the reflection object in phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/Php/PhpClassReflectionExtension.php:576 #0 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/Php/PhpClassReflectionExtension.php(576): ReflectionClass->getTraitAliases() #1 

Maybe it's related to some internal state of ReflectionClass or maybe the way how it was obtained, but calling `ReflectionClass->getTraitAliases()` always results in a crash on PHP 8.1. It works on PHP 8.0.

Hopefully this gives you enough information to track it down. Thanks.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-17 13:43 UTC]
Any non-simple way of reproducing it (like running phpstan tests?) I don't think this is directly related to getTraitAliases(), the exception indicates that the ReflectionClass object is not fully uninitialized.
 [2021-11-17 13:47 UTC] ondrej at mirtes dot cz
There’s a repository that shows the bug inside Docker:

I tried to reproduce it outside of PHPStan but with no luck :/ It also doesn’t help thst the Laravel classes and traits are so huge.
 [2021-11-17 14:28 UTC]
-Status: Open +Status: Verified
 [2021-11-17 14:28 UTC]
Thanks, I can reproduce with the provided repo.
 [2021-11-17 14:55 UTC]
Automatic comment on behalf of nikic
Log: Fix bug #81630: Don't claim known hash in getTraitAliases()
 [2021-11-17 14:55 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Sep 22 13:01:24 2023 UTC