If I want myFunction
to take $myVariable
and assign to it an instance of SomeClass
, I know I can do this:
class SomeClass { }
function myFunction(&$myVariable) {
$myVariable = new SomeClass();
}
myFunction($myVariable);
var_dump($myVariable);
However, I would like to be able to have myFunction
operate like this:
class SomeClass { }
function myFunction($args = array()) {
if(isset($args['something'])) {
$$args['something'] = new SomeClass();
}
}
myFunction(array(
'something' => $myVariable
));
var_dump($myVariable);
Is there any way to achieve this?