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 25, 2024
1 parent 1dd4dc4 commit f280e3f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function register()
{
return [
T_ANON_CLASS,
T_PARENT,
T_SELF,
T_STATIC,
T_STRING,
T_VARIABLE,
];
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,6 +45,9 @@ public function getErrorList($testFile='CallTimePassByReferenceUnitTest.1.inc')
50 => 1,
51 => 1,
54 => 1,
62 => 1,
63 => 1,
64 => 1,
];

default:
Expand Down

0 comments on commit f280e3f

Please sign in to comment.