Skip to content

Commit

Permalink
Generic/CallTimePassByReference: listen to self, parent and static
Browse files Browse the repository at this point in the history
This commit changes the CallTimePassByReference sniff to listen to the
T_PARENT, T_SELF, and T_STATIC tokens. From now on the sniff will
trigger errors when one of those tokens is used to instantiate a class
containing a variable passed by reference.
  • Loading branch information
rodrigoprimo committed Apr 30, 2024
1 parent 15d9d9e commit 7a96d3d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function register()
T_STRING,
T_VARIABLE,
T_ANON_CLASS,
T_PARENT,
T_SELF,
T_STATIC,
];

}//end register()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,15 @@ $instance = new MyClass(&$a);

$anon = new class($a) {};
$anon = new class(&$a) {};

class Foo extends Bar {
function myMethod() {
$a = new static($var);
$b = new self($var);
$c = new parent($var);

$d = new static(&$var);
$e = new self(&$var);
$f = new parent(&$var);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ public function getErrorList($testFile='CallTimePassByReferenceUnitTest.1.inc')
50 => 1,
51 => 1,
54 => 1,
62 => 1,
63 => 1,
64 => 1,
];

default:
return [];
}
}//end switch

}//end getErrorList()

Expand Down

0 comments on commit 7a96d3d

Please sign in to comment.