js-construct-direct-call.phpt 805 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. --TEST--
  2. Test V8::executeString() : Test PHP object construction controlled by JavaScript (non-construction call)
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. $v8 = new V8Js();
  8. class Greeter {
  9. function sayHello($a) {
  10. echo "Hello $a\n";
  11. }
  12. }
  13. $v8->greeter = new Greeter();
  14. $v8->executeString('
  15. function JsGreeter() { };
  16. JsGreeter.prototype.sayHello = function(a) {
  17. print("Hello " + a + "\n");
  18. };
  19. jsGreeter = new JsGreeter();
  20. jsGreeter.sayHello("Paul");
  21. print(jsGreeter.constructor());
  22. print("\n");
  23. // ----- now the same using v8Js -----
  24. PHP.greeter.sayHello("John");
  25. print(PHP.greeter.constructor());
  26. print("\n");
  27. ');
  28. ?>
  29. ===EOF===
  30. --EXPECT--
  31. Hello Paul
  32. undefined
  33. Hello John
  34. undefined
  35. ===EOF===