The error "Warning: Undefined variable $a" is because the variable $a is defined inside the anonymous function assigned to $a, and it is not in the scope of the anonymous function assigned to $b.
In other words, the variable $a is not defined in the global scope, so when the function assigned to $b tries to access it, PHP cannot find it and generates an "Undefined variable" warning.
To fix this error, you need to pass $a as an argument to the function assigned to $b or use the use keyword to import the $a variable into the function assigned to $b:
Option 1: Passing $a as an argument to $b
$a = function($v) {
return $v;
};
$b = function($v, $a) {
return $a($v);
};
echo $b('something', $a);
Option 2: Using use keyword to import $a into $b
$a = function($v) {
return $v;
};
$b = function($v) use ($a) {
return $a($v);
};
echo $b('something');