2

The following code...

function getInstance() {
  echo "(getInstance() called)\n";

  return new TestClass();
}

class TestClass {
  function someMethod() {
    echo "someMethod called. Awesome!\n";
  }
}

$sandbox = new Runkit_Sandbox();
$sandbox['parent_access'] = true;
$sandbox['parent_call'] = true;

$sandbox->eval(
  '$PARENT = new Runkit_Sandbox_Parent; '.
  '$PARENT->getInstance()->someMethod();'
);

leads to this output on my PHP 5.4.10 build:

(getInstance() called)
PHP Warning:  Runkit_Sandbox::eval(): Error executing sandbox code in /home/projpf/_test/sandbox_test2.php on line 24

Apparently it's not possible to call a method from within the sandbox that has been declared outside the sandbox. Is this a restriction of Runkit or am I doing something wrong?

In case you're wondering what I'm trying to do: I'd like to convert my PHP web scripts to long-running workers accepting HTTP requests via RabbitMQ. Those scripts sometimes have to do heavy initializations that could be cached as variables but not via any external cache. A sandbox would allow the worker process to load the correct handler script without leaving any traces - except for that data that should be explicitely cached, which in this case would be a high number of class instances.

4

0 回答 0