You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
2.2.13: "Cannot redeclare function" fatal error with php-standard-library/type package #15184
PHPStan 2.2.12 works fine, but after updating to v2.2.13 phpstan analyze crashes with the following error on a project requiring php-standard-library/type ^6.2:
-- -------------------------------------------------------------------------
Error
-- -------------------------------------------------------------------------
Child process error (exit code 255): Fatal error: Cannot redeclare
function Psl\Type\optional() (previously declared in
.../vendor/php-standard-library/type/src/Psl/Type/optional.php:18) in
.../vendor/php-standard-library/type/src/Psl/Type/optional.php on line 18
Stack trace:
#0 phar://.../phpstan.phar/vendor/composer/ClassLoader.php(427):
{closure:Composer\Autoload\ClassLoader::initializeIncludeClosure():575}('...')
#1 phar://.../src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php(271):
Composer\Autoload\ClassLoader->loadClass('Psl\Type\optional')
#2 phar://.../src/Reflection/BetterReflection/SourceLocator/FileReadTrapStreamWrapper.php(69):
AutoloadSourceLocator::{closure:...locateClassByName():264}()
#3 phar://.../src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php(264):
FileReadTrapStreamWrapper::withStreamWrapperOverride(Object(Closure))
...
#10 phar://.../src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php(38):
BetterReflectionProvider->hasClass('Psl\Type\optional')
#11 phar://.../src/Reflection/ClassReflection.php(878):
MemoizingReflectionProvider->hasClass('Psl\Type\optional')
#12 [internal function]: ClassReflection->is('Psl\Type\optional')
#13 phar://.../src/Analyser/MutatingScope.php(2056):
PHPStanTurbo\ScopeOps::invalidateExpressionEntries(...)
It looks like this is caused by 2.2.13 spawning workers with OPcache enabled, which breaks FileReadTrapStreamWrapper. OPcache serves an already-cached file from shared memory without going through the stream wrapper, so the autoloader's include re-executes the file and crashes.
Code snippet that reproduces the problem
No response
Expected output
No error.
Environment
PHPStan 2.2.13 (phar, installed via Composer), config includes php-standard-library/phpstan-extension ^2.1, level: 8
PHP 8.5.9 NTS, VC++ 2022 x64, Windows 11 Pro
php-standard-library/type 6.2
Did PHPStan help you today? Did it make you happy in any way?
Thank you for all the efforts to improve quality and performance!
Activity
mergeable commentedon Sep 4, 2026
This bug report is missing a link to reproduction at phpstan.org/try.
It will most likely be closed after manual review.
[Composer] Added conflict with phpstan/phpstan 2.2.13
Evict the OPcache entry for a trapped path before the autoloader incl…
Ask Composer's autoloaders for the file instead of letting them inclu…
Ask Composer's autoloaders for the file instead of letting them inclu…
Ask Composer's autoloaders for the file instead of letting them inclu…
Ask Composer's autoloaders for the file instead of letting them inclu…
Ask Composer's autoloaders for the file instead of letting them inclu…
Ask Composer's autoloaders for the file instead of letting them inclu…
Ask Composer's autoloaders for the file instead of letting them inclu…
Ask Composer's autoloaders for the file instead of letting them inclu…