I have a class that requires a variable that is defined out of the scope of it. So i tried using global
but, this causes this error:
syntax error, unexpected 'global' (T_GLOBAL), expecting function (T_FUNCTION)
I am unsure if I have put it in the wrong place or using the global keyword incorrectly.
My code looks like this:
$data = new testClass();
class System
{
private $values;
global $data;
public function __construct()
{
}
public function test()
{
return $data->get();
}
}
$system = new System();
echo $system->test();
So i was wondering how do I get the $data
variable to be defined in my class? My use of global seems to be incorrect, I also put the global declaration in the __contrust()
function but that didn't work either.