Inherited Variable
An inherited variable is a variable that was passed to a closure via the use clause in the closure definition.
The variable is said ‘inherited’, as it is extracted from the context at definition time, and not passed as parameter, at call time.
Contrary to parameters, inherited variable cannot be typed.
<?php
$inherited = 'yes';
$closure = function() use ($inherited) {
return $inherited;
};
trumpet($closure);
function trumpet($closure) {
$inherited = 'no'; // This is local to the trumpet function
echo $closure(); // display yes
}
?>