Skip to content

Commit 357630a

Browse files
committed
Update the regex for variable interpolation.
1 parent e6d9cd0 commit 357630a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

classes/tests/critical.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getTests() {
4848
* @return boolean Line matches test.
4949
*/
5050
public function _variableInterpolation($line) {
51-
$regex = "#(?:(?:->|\\$)\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+|::\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+\[.+?\]\(.*?\))#i";
51+
$regex = "#(((::|->)\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)+\\[[^\s]+\\]\()|(->\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*\\[)|(\\$\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*\\[)|(^\s*?global.*?\\$\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)#i"; //@LawnGnome's regex from Twitter; modified and extended to support global simple variable change.
5252
if (preg_match($regex, $line)) {
5353
return true;
5454
}

testcases.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2-
$$foo['bar']['baz']; // interpreted as ($$foo)['bar']['baz']
3-
$foo->$bar['baz']; // interpreted as ($foo->$bar)['baz']
4-
$foo->$bar['baz'](); // interpreted as ($foo->$bar)['baz']()
5-
Foo::$bar['baz'](); // interpreted as (Foo::$bar)['baz']()
6-
global $$foo->bar;
2+
$$foo['bar']['baz']; //Interpreted as ($$foo)['bar']['baz']
3+
$foo->$bar['baz']; //Interpreted as ($foo->$bar)['baz']
4+
$foo->$bar['baz'](); //Interpreted as ($foo->$bar)['baz']()
5+
Foo::$bar['baz'](); //Interpreted as (Foo::$bar)['baz']()
6+
global $$foo->bar; //The global keyword now only accepts simple variables.
77
$array["a"] =& $array["b"]; //Array value created by reference.
88
list() = "string";
99
list() = $a;

0 commit comments

Comments
 (0)