phpstan: PHP Fatal error: Allowed memory size of XXXXX bytes exhausted
Bug report
php ./vendor/bin/phpstan --version
PHPStan - PHP Static Analysis Tool 1.9.3
php -v
PHP 8.1.13 (cli) (built: Nov 26 2022 14:07:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.13, Copyright (c) Zend Technologies
with Zend OPcache v8.1.13, Copyright (c), by Zend Technologies
When parsing some PHP files it stuck with a recursive load and memory is drained:
php ./vendor/bin/phpstan analyse app --memory-limit=1G
Note: Using configuration file /home/lito/www/phpstan-memory-exhausted/phpstan.neon.
6/6 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
-- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Error
-- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Child process error (exit code 255): PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 262144 bytes) in
phar:///home/lito/www/phpstan-memory-exhausted/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php on line 559
PHPStan process crashed because it reached configured PHP memory limit: 1G
Increase your memory limit in php.ini or run PHPStan with --memory-limit CLI option.
PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 2621440 bytes) in /home/lito/www/phpstan-memory-exhausted/vendor/symfony/console/Output/AnsiColorMode.php on line 73
-- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code snippet that reproduces the problem
git clone https://github.com/eusonlito/phpstan-memory-exhausted.git
cd phpstan-memory-exhausted
composer install
php ./vendor/bin/phpstan analyse app --memory-limit=1G
- Deleting methods
payloadRow,payloadRowIsSameandpayloadRowOtheratapp/Domains/Log/Model/Traits/Payload.phpit works - Deleting database migration table
logatdatabase/migrations/2021_01_14_000000_base.phpit works
Expected output
Finish without error
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (9 by maintainers)
@eusonlito Thank you for your kind words! 😃
Fixed the problem: https://github.com/phpstan/phpstan-src/commit/a7fed03bbf1bef545c8afcbf6c906ac93b34c876
@rajyan I had to modify some conditional types tests, the results are a bit worse now, but I think the code makes more sense - if we’re assigning a variable, we want to invalidate everything.
This is the snippet of the stack trace of the infinite recursion: