diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 4997ff65e7..79178a0cb2 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -3500,6 +3500,11 @@ private function shouldInvalidateExpression(string $exprStringToInvalidate, Expr return false; } + // Variables will not contain traversable expressions. skip the NodeFinder overhead + if ($expr instanceof Variable && is_string($expr->name)) { + return $exprStringToInvalidate === $this->getNodeKey($expr); + } + $nodeFinder = new NodeFinder(); $expressionToInvalidateClass = get_class($exprToInvalidate); $found = $nodeFinder->findFirst([$expr], function (Node $node) use ($expressionToInvalidateClass, $exprStringToInvalidate): bool {