Let's create closure:
class Example {
function get($arg) {
return function() use ($arg) {
return $arg;
}
}
}
$closure = (new Example())->get("value");
Take a $this
attribute:
$ref = new \ReflectionFunction($closure);
$refThis = $ref->getClosureThis();
Take scope variables from use
statement:
$refUse = $ref->getStaticVariables();
assertEquals($closure(), $refUse['arg']);