*/
public function __construct(Shell $__psysh__)
{
- $exec = function () use ($__psysh__) {
+ $this->setClosure($__psysh__, function () use ($__psysh__) {
try {
// Restore execution scope variables
extract($__psysh__->getScopeVariables(false));
$__psysh__->setScopeVariables(get_defined_vars());
return $_;
- };
+ });
+ }
+ /**
+ * Set the closure instance.
+ *
+ * @param Shell $psysh
+ * @param \Closure $closure
+ */
+ protected function setClosure(Shell $shell, \Closure $closure)
+ {
if (self::shouldBindClosure()) {
- $that = $__psysh__->getBoundObject();
+ $that = $shell->getBoundObject();
if (is_object($that)) {
- $this->closure = $exec->bindTo($that, get_class($that));
+ $closure = $closure->bindTo($that, get_class($that));
} else {
- $this->closure = $exec->bindTo(null, null);
+ $closure = $closure->bindTo(null, $shell->getBoundClass());
}
-
- return;
}
- $this->closure = $exec;
+ $this->closure = $closure;
}
/**