Skip to content

Commit 25cb765

Browse files
committed
This caused bad memory leak
1 parent c1812e7 commit 25cb765

3 files changed

Lines changed: 6 additions & 30 deletions

File tree

src/Reflection/BetterReflection/Reflector/MemoizingClassReflector.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
final class MemoizingClassReflector extends ClassReflector
99
{
1010

11-
/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionClass|\Throwable> */
11+
/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionClass> */
1212
private array $reflections = [];
1313

1414
/**
@@ -22,18 +22,10 @@ public function reflect(string $className): Reflection
2222
{
2323
$lowerClassName = strtolower($className);
2424
if (isset($this->reflections[$lowerClassName])) {
25-
if ($this->reflections[$lowerClassName] instanceof \Throwable) {
26-
throw $this->reflections[$lowerClassName];
27-
}
2825
return $this->reflections[$lowerClassName];
2926
}
3027

31-
try {
32-
return $this->reflections[$lowerClassName] = parent::reflect($className);
33-
} catch (\Throwable $e) {
34-
$this->reflections[$lowerClassName] = $e;
35-
throw $e;
36-
}
28+
return $this->reflections[$lowerClassName] = parent::reflect($className);
3729
}
3830

3931
}

src/Reflection/BetterReflection/Reflector/MemoizingConstantReflector.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
final class MemoizingConstantReflector extends ConstantReflector
99
{
1010

11-
/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionConstant|\Throwable> */
11+
/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionConstant> */
1212
private array $reflections = [];
1313

1414
/**
@@ -21,18 +21,10 @@ final class MemoizingConstantReflector extends ConstantReflector
2121
public function reflect(string $constantName): Reflection
2222
{
2323
if (isset($this->reflections[$constantName])) {
24-
if ($this->reflections[$constantName] instanceof \Throwable) {
25-
throw $this->reflections[$constantName];
26-
}
2724
return $this->reflections[$constantName];
2825
}
2926

30-
try {
31-
return $this->reflections[$constantName] = parent::reflect($constantName);
32-
} catch (\Throwable $e) {
33-
$this->reflections[$constantName] = $e;
34-
throw $e;
35-
}
27+
return $this->reflections[$constantName] = parent::reflect($constantName);
3628
}
3729

3830
}

src/Reflection/BetterReflection/Reflector/MemoizingFunctionReflector.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
final class MemoizingFunctionReflector extends FunctionReflector
99
{
1010

11-
/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionFunction|\Throwable> */
11+
/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionFunction> */
1212
private array $reflections = [];
1313

1414
/**
@@ -22,18 +22,10 @@ public function reflect(string $functionName): Reflection
2222
{
2323
$lowerFunctionName = strtolower($functionName);
2424
if (isset($this->reflections[$lowerFunctionName])) {
25-
if ($this->reflections[$lowerFunctionName] instanceof \Throwable) {
26-
throw $this->reflections[$lowerFunctionName];
27-
}
2825
return $this->reflections[$lowerFunctionName];
2926
}
3027

31-
try {
32-
return $this->reflections[$lowerFunctionName] = parent::reflect($functionName);
33-
} catch (\Throwable $e) {
34-
$this->reflections[$lowerFunctionName] = $e;
35-
throw $e;
36-
}
28+
return $this->reflections[$lowerFunctionName] = parent::reflect($functionName);
3729
}
3830

3931
}

0 commit comments

Comments
 (0)