Skip to content

Commit fa6e01c

Browse files
committed
Handle superglobals within double-quoted strings correctly.
1 parent 3f0ddc0 commit fa6e01c

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,9 @@ protected function processVariableInString(
12411241
if ($this->checkForThisWithinClass($phpcsFile, $stackPtr, $varName, $currScope)) {
12421242
continue;
12431243
}
1244+
if ($this->checkForSuperGlobal($phpcsFile, $stackPtr, $varName, $currScope)) {
1245+
return;
1246+
}
12441247
$this->markVariableRead($varName, $stackPtr, $currScope);
12451248
if ($this->isVariableUndefined($varName, $stackPtr, $currScope) === true) {
12461249
$phpcsFile->addWarning("Variable %s is undefined.", $stackPtr,

Tests/CodeAnalysis/VariableAnalysisUnitTest.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,5 @@ function function_with_superglobals() {
374374
echo print_r($_SESSION, true);
375375
echo print_r($_REQUEST, true);
376376
echo print_r($_ENV, true);
377+
echo "$GLOBALS['whatever']";
377378
}

0 commit comments

Comments
 (0)