From 8c7cd1ce8ed5701b813eeae26ba1bcd38af6681c Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Tue, 27 Jan 2026 06:22:51 +0000 Subject: [PATCH] Allow literal string dynamic property --- src/Rules/VariableVariables/VariablePropertyFetchRule.php | 4 ++++ tests/Rules/VariableVariables/data/properties.php | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Rules/VariableVariables/VariablePropertyFetchRule.php b/src/Rules/VariableVariables/VariablePropertyFetchRule.php index 760bff69..44fc32e1 100644 --- a/src/Rules/VariableVariables/VariablePropertyFetchRule.php +++ b/src/Rules/VariableVariables/VariablePropertyFetchRule.php @@ -44,6 +44,10 @@ public function processNode(Node $node, Scope $scope): array return []; } + if ($scope->getType($node->name)->isLiteralString()->yes()) { + return []; + } + $fetchedOnType = $scope->getType($node->var); foreach ($fetchedOnType->getObjectClassNames() as $referencedClass) { if (!$this->reflectionProvider->hasClass($referencedClass)) { diff --git a/tests/Rules/VariableVariables/data/properties.php b/tests/Rules/VariableVariables/data/properties.php index 703b94e0..a0bfc883 100644 --- a/tests/Rules/VariableVariables/data/properties.php +++ b/tests/Rules/VariableVariables/data/properties.php @@ -15,13 +15,14 @@ class Bar extends stdClass } function (stdClass $std, Foo $foo, Bar $bar) { - $str = 'str'; + $str = sprintf('str%d', time()); $std->foo; $std->$str; $foo->foo; $foo->$str; + $foo->{'str'}; $bar->foo; $bar->$str;