-
-
Notifications
You must be signed in to change notification settings - Fork 932
Closed
phpstan/phpstan-src
#4560Description
Bug report
while phpstan-src development I accidentally stumbled over this problem:
➜ phpstan-src git:(2.1.x) ✗ make phpstan
php bin/phpstan clear-result-cache -q && php -d memory_limit=448M bin/phpstan
Note: Using configuration file /Users/staabm/workspace/phpstan-src/phpstan.neon.dist.
2187/2187 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
PHP Fatal error: Allowed memory size of 469762048 bytes exhausted (tried to allocate 4096 bytes) in /Users/staabm/workspace/phpstan-src/vendor/shipmonk/dead-code-detector/src/Rule/DeadCodeRule.php on line 267
Fatal error: Allowed memory size of 469762048 bytes exhausted (tried to allocate 4096 bytes) in /Users/staabm/workspace/phpstan-src/vendor/shipmonk/dead-code-detector/src/Rule/DeadCodeRule.php on line 267
PHPStan process crashed because it reached configured PHP memory limit: 448M
Increase your memory limit in php.ini or run PHPStan with --memory-limit CLI option.
make: *** [phpstan] Error 255
repro
- checkout phpstan/phpstan-src@25f1cd2
- apply this diff:
diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php
index 3b7a72baaa..10affa9895 100644
--- a/src/Type/ObjectType.php
+++ b/src/Type/ObjectType.php
@@ -1583,8 +1583,10 @@ class ObjectType implements TypeWithClassName, SubtractableType
{
$classReflection = $this->getClassReflection();
if ($classReflection === null) {
+ $y = 1;
return TrinaryLogic::createMaybe();
}
+ echo $y;
if ($classReflection->is($className)) {
return TrinaryLogic::createYes();- run
make phpstan
➜ phpstan-src git:(de-dup) ✗ time php bin/phpstan analyze src/Type/ObjectType.php --debug
Note: Using configuration file /Users/staabm/workspace/phpstan-src/phpstan.neon.dist.
/Users/staabm/workspace/phpstan-src/src/Type/ObjectType.php
------ ---------------------------------
Line ObjectType.php
------ ---------------------------------
1589 Undefined variable: $y
🪪 variable.undefined
at src/Type/ObjectType.php:1589
...
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
1589 Warning: Undefined variable $y
at src/Type/ObjectType.php:1589
------ ---------------------------------
[ERROR] Found 878 errors
php bin/phpstan analyze src/Type/ObjectType.php --debug 2.01s user 0.18s system 99% cpu 2.188 total
sometimes it finds the very same error a few hundred-thousand times per line and finally crashes.
I think it is unlikely to be hit in practice, but it might happen while building custom rules.
and finding the root cause might not be obvious, why PHPStan started crashing by adding a new rule.
Code snippet that reproduces the problem
No response
Expected output
no out of memory error
Did PHPStan help you today? Did it make you happy in any way?
No response
Metadata
Metadata
Assignees
Labels
No labels