Is it possible to pass an object to the constructor of a PHP class and set this object as a global variable that can be used by other functions of the class?
For instance:
class test {
function __construct($arg1, $arg2, $arg3) {
global $DB, $ode, $sel;
$DB = arg1;
$ode = arg2;
$sel = $arg3;
}
function query(){
$DB->query(...);
}
}
When I try to do this, I get the error "Member function call on non-object." Is there any way to do this? Otherwise, I have to pass the objects to each individual function directly.
Thank!
source
share