Sometimes we will find that a static class method uses a global
variable like so:
1 <?php 2 class Foo 3 { 4 static public function doSomething($baz) 5 { 6 global $bar; 7 // ... do something with $bar ... 8 } 9 } 10 ?>
This is a problem because there is no constructor to which we can move the global
variable as a property. There are two options here.
The first option is to pass all the needed globals as parameters on the static method itself, thereby changing the signature of the method:
1 <?php 2 class Foo 3 { 4 static public function doSomething($bar, $baz) 5 { 6 // ... do something with $bar ... 7 } 8 } 9 ?>
We would then search the codebase for all uses of Foo::doSomething(
and pass the $bar
value each time. For that reason, I suggest adding the new parameters to the beginning of the signature, rather than to the end, because it makes search-and-replace much easier. For example:
Search for:
Foo::doSomething\(
Replace with...