I have a PHP class method which is using a static function from with a another class. How do i enable that static function to modify variables within the calling class.. Example as follows:
PARENT:
class sys_core
{
public $test = 'no';
// --------------------
public function __construct()
{
}
// --------------------
public function init()
{
sys_loader::load_config('123');
print $this->test;
}
// --------------------
// --------------------
// --------------------
// --------------------
// --------------------
} // END Class
STATIC CLASS
class sys_loader
{
private $registry = array();
// --------------------
public static function load_config($file)
{
$this->test = 'yes';
}
// --------------------
// --------------------
// --------------------
// --------------------
} // END Class
ERROR:
Fatal error: Using $this when not in object context
As I see it, sys_loader can modify sys_core’s $test 3 ways:
1) sys_loader is passed a reference to sys_core->test,
2) sys_loader returns a new value for it or
3) equip sys_core with a setter for $test and pass sys_loader a reference to sys_core.
With that reference, sys_loader can access whatever variables and functions sys_core allows.
Here are the bits I changed/added to make #3 work:
Example use:
Output:
123yes
class sys_core
class sys_loader