Skip to content

Commit

Permalink
PHP 8.0 | Zend/ValidVariableName: allow for nullsafe object operator
Browse files Browse the repository at this point in the history
Includes unit test.
  • Loading branch information
jrfnl committed Sep 1, 2020
1 parent 85f3521 commit 49a8d01
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ protected function processVariable(File $phpcsFile, $stackPtr)
}

$objOperator = $phpcsFile->findNext([T_WHITESPACE], ($stackPtr + 1), null, true);
if ($tokens[$objOperator]['code'] === T_OBJECT_OPERATOR) {
if ($tokens[$objOperator]['code'] === T_OBJECT_OPERATOR
|| $tokens[$objOperator]['code'] === T_NULLSAFE_OBJECT_OPERATOR
) {
// Check to see if we are using a variable from an object.
$var = $phpcsFile->findNext([T_WHITESPACE], ($objOperator + 1), null, true);
if ($tokens[$var]['code'] === T_STRING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ $anonClass = new class() {
$bar_foo = 3;
}
};

echo $obj?->varName;
echo $obj?->var_name;
echo $obj?->varName;
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function getErrorList()
99 => 1,
113 => 1,
116 => 1,
121 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 49a8d01

Please sign in to comment.