I'm calling a function from another class and instead of creating a new object every time which is the easiest way I was trying to create the object in the constructor and set it to a global var for the class and then call functions when need, something like below.
This is the other way but would involve creating an object for each function that required the function in the second class.
Just looking for advice on the best way forward, thanks.
Code:
class one {
var $object;
public function __construct() {
$this->object = new two();
$this->test();
}
private function test() {
$var = $this->object->funcInClassTwo();
}
}
Code:
class one {
public function __construct() {
$this->test();
}
private function test() {
$object = new two();
$var = $object->funcInClassTwo();
}
}