What’s the best practice with PHP 5.6+? What is the more sparing method? Relating to resources / memory / speed.
Pass a variable by reference to a function. I don’t need to modify the variable:
$bigClass = new MyBigClass();
class MyClass extends AnotherClass
{
protected $obj;
function __construct(
amespace\interface &$obj) {
$this->obj =& $obj;
}
public function function1() {
$this->obj->doThings();
}
private function function2() {
$this->obj->otherThings();
}
public function function3() {
// and so on ...
}
}
$my_class = new MyClass($bigClass);
// $my_class->...
or should I use the way with the global Keyword:
$bigClass = new MyBigClass();
class MyClass extends AnotherClass
{
function __construct() { }
public function function1() {
global $bigClass;
$bigClass->doThings();
}
private function function2() {
global $bigClass;
$bigClass->otherThings();
}
public function function3() {
// and so on ...
}
}
$my_class = new MyClass();
// $my_class->...
Which method consumes the most resources and is slow?
Or to be nothing to speak of?
Thanks