I have a closure that is a global
variable and I would like to run it in a class I made. However, when I try the following code, I get the error, Exception: Call to undefined method TestClass::globalFunction()
.
Here is what I'm trying:
$globalFunction = function($var){
echo "works $var";
};
class TestClass{
private $globalFunction;
function __construct(){
$this->globalFunction = $GLOBALS['globalFunction'];
}
function testFunc(){
$this->globalFunction('a');
}
}
$arr = new TestClass();
$arr->testFunc();