I have a very simple class:
class MyClass
{
public function someFunction()
{
echo array_key_exists( 'dynamicVariable', $GLOBALS ) ? 'true' : 'false';
}
}
I want to define a variable 'on the fly' inside 'someFunction', but I can't seem to figure out how to do this inside function scope.
$classInstance = new MyClass();
$varName = 'dynamicVariable';
$classInstance->$varName;
What I want to do:
$classInstance = new MyClass();
$varName = 'dynamicVariable';
$classInstance->functionScopeReference->$varName;
$classInstance->myFunction(); <-- this will print TRUE
How can do the same thing, but define it in someFunction scope, instead of MyClass scope? Thanks