test_method.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // Test class
  3. class Testing
  4. {
  5. public $foo = 'ORIGINAL';
  6. private $my_private = 'arf'; // Should not show in JS side
  7. protected $my_protected = 'argh'; // Should not show in JS side
  8. function mytest($a, $b, $c = NULL)
  9. {
  10. var_dump(func_get_args());
  11. }
  12. }
  13. $a = new V8Js();
  14. $a->myobj = new Testing();
  15. $a->executeString("PHP.myobj.mytest('arg1', 'arg2');", "test1.js");
  16. $a->executeString("PHP.myobj.mytest(true, false, 1234567890);", "test2.js");
  17. $a->executeString("PHP.myobj.mytest(3.14, 42, null);", "test3.js");
  18. // Invalid parameters
  19. try {
  20. $a->executeString("PHP.myobj.mytest();", "test4.js");
  21. } catch (V8JsScriptException $e) {
  22. echo $e->getMessage(), "\n";
  23. }
  24. try {
  25. $a->executeString("PHP.myobj.mytest('arg1', 'arg2', 'arg3', 'extra_arg');", "test5.js");
  26. } catch (V8JsScriptException $e) {
  27. echo $e->getMessage(), "\n";
  28. }
  29. // Array / Object
  30. try {
  31. // date_default_timezone_set("UTC");
  32. $a->executeString("date = new Date('September 8, 1975 09:00:00'); PHP.print(date); PHP.myobj.mytest(date, PHP.myobj, new Array(1,2,3));", "test6.js");
  33. } catch (V8JsScriptException $e) {
  34. var_dump($e);
  35. }
  36. try {
  37. $a->executeString("PHP.myobj.mytest(PHP.myobj, new Array(1,2,3), new Array('foo', 'bar', PHP.myobj));", "test7.js");
  38. } catch (V8JsScriptException $e) {
  39. var_dump($e);
  40. }