So aside from the obvious readability improvement (to me anyway), is there a performance benefit gained in PHP when assigning a local variable to the value of an element in a superglobal array, versus accessing the element's value directly?
For example, given a class that repeatedly uses: $_SERVER['REQUEST_URI']
as an argument for a number of functions, is there a performance benefit to creating a class property (or for that matter a local variable with class scope) and using the variable directly? I have a C# background and I have learned from experience that using the local variable does offer a performance benefit.
$url = $_SERVER['REQUEST_URI'];
public function doSomething() {
echo $this->url;
}
public function doSomethingElse() {
echo $this->url;
}
versus
public function doSomething() {
echo $_SERVER['REQUEST_URI'];
}
public function doSomethingElse() {
echo $_SERVER['REQUEST_URI'];
}