object_method_call.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 (V8JsException $e) {
  22. echo $e->getMessage(), "\n";
  23. }
  24. try {
  25. $a->executeString("PHP.myobj.mytest('arg1', 'arg2', 'arg3', 'extra_arg');", "test5.js");
  26. } catch (V8JsException $e) {
  27. echo $e->getMessage(), "\n";
  28. }
  29. try {
  30. date_default_timezone_set("UTC");
  31. echo "\nTEST: Javascript Date -> PHP DateTime\n";
  32. echo "======================================\n";
  33. $a->executeString("date = new Date('September 8, 1975 09:00:00'); print(date + '\\n'); PHP.myobj.mytest(date, 'foo');", "test6.js");
  34. } catch (V8JsException $e) {
  35. echo $e->getMessage(), "\n";
  36. }
  37. // Array / Object
  38. try {
  39. $a->executeString("PHP.myobj.mytest(PHP.myobj, new Array(1,2,3), new Array('foo', 'bar', PHP.myobj));", "test7.js");
  40. } catch (V8JsException $e) {
  41. var_dump($e);
  42. }
  43. ?>
  44. ===EOF===