0
$function = function($parameter) use ($variable)
{
  //Do some stuff
  $function($something); //When I do this i get variable undefined '$function'
}

How can I call the function?

I've already tried to call the parent or redefine the variable but i'd like a more compact solution than just redefining a whole new function and using that.

VJamie
  • 616
  • 3
  • 14

1 Answers1

1

The general trick here is to use () the Closure holding variable by reference:

$function = function($parameter) use ($variable, &$function) {
    //Do some stuff
    $function($something);
}
bwoebi
  • 23,637
  • 5
  • 58
  • 79