closures_dynamic.phpt 585 B

123456789101112131415161718192021222324252627282930
  1. --TEST--
  2. Test V8::executeString() : Dynamic closure call test
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. class Foo
  8. {
  9. public static function bar($s)
  10. {
  11. return 'Hello ' . $s;
  12. }
  13. }
  14. $a = new V8Js();
  15. $b = array('Foo', 'bar');
  16. $a->func = function ($arg) use ($b) { return call_user_func($b, $arg); };
  17. try {
  18. $a->executeString('print(PHP.func + "\n"); print(PHP.func("world") + "\n");', "closure_test.js");
  19. } catch (V8JsScriptException $e) {
  20. echo $e->getMessage(), "\n";
  21. }
  22. ?>
  23. ===EOF===
  24. --EXPECT--
  25. [object Closure]
  26. Hello world
  27. ===EOF===