Skip to content

Commit 8d7c3ff

Browse files
VasekPurchartondrejmirtes
authored andcommitted
Do not evaluate constructors as having side effects by default
1 parent c5d0902 commit 8d7c3ff

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,7 @@ function (MutatingScope $scope) use ($expr, $nodeCallback, $context): Expression
19961996
$scope = $result->getScope();
19971997
if ($methodReflection !== null) {
19981998
$hasSideEffects = $methodReflection->hasSideEffects();
1999-
if ($hasSideEffects->yes()) {
1999+
if ($hasSideEffects->yes() || $methodReflection->getName() === '__construct') {
20002000
$scope = $scope->invalidateExpression($expr->var, true);
20012001
foreach ($expr->getArgs() as $arg) {
20022002
$scope = $scope->invalidateExpression($arg->value, true);
@@ -2118,7 +2118,10 @@ function (MutatingScope $scope) use ($expr, $nodeCallback, $context): Expression
21182118
if (
21192119
$methodReflection !== null
21202120
&& !$methodReflection->isStatic()
2121-
&& $methodReflection->hasSideEffects()->yes()
2121+
&& (
2122+
$methodReflection->hasSideEffects()->yes()
2123+
|| $methodReflection->getName() === '__construct'
2124+
)
21222125
&& $scopeFunction instanceof MethodReflection
21232126
&& !$scopeFunction->isStatic()
21242127
&& $scope->isInClass()
@@ -2131,7 +2134,7 @@ function (MutatingScope $scope) use ($expr, $nodeCallback, $context): Expression
21312134
}
21322135

21332136
if ($methodReflection !== null) {
2134-
if ($methodReflection->hasSideEffects()->yes()) {
2137+
if ($methodReflection->hasSideEffects()->yes() || $methodReflection->getName() === '__construct') {
21352138
foreach ($expr->getArgs() as $arg) {
21362139
$scope = $scope->invalidateExpression($arg->value, true);
21372140
}

src/Reflection/Php/PhpMethodReflection.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,6 @@ public function hasSideEffects(): TrinaryLogic
413413
return TrinaryLogic::createFromBoolean(!$this->isPure);
414414
}
415415

416-
if ($isVoid) {
417-
return TrinaryLogic::createYes();
418-
}
419-
420416
return TrinaryLogic::createMaybe();
421417
}
422418

0 commit comments

Comments
 (0)