Can you pass in a $this variable to use in a function in the "global" space like you can in javascript? I know $this is meant for classes, but just wondering. I'm trying to avoid using the "global" keyword.
For example:
class Example{
function __construct(){ }
function test(){ echo 'something'; }
}
function outside(){ var_dump($this); $this->test(); }
$example = new Example();
call_user_func($example, 'outside', array('of parameters')); //Where I'm passing in an object to be used as $this for the function
In javascript I can use the call
method and assign a this
variable to be used for a function. Was just curious if the same sort of thing can be accomplished with PHP.