object_method_call.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. --TEST--
  2. Test V8::executeString() : Calling methods of object passed from PHP
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. // Test class
  8. class Testing
  9. {
  10. public $foo = 'ORIGINAL';
  11. private $my_private = 'arf'; // Should not show in JS side
  12. protected $my_protected = 'argh'; // Should not show in JS side
  13. function mytest($a, $b, $c = NULL)
  14. {
  15. var_dump(func_get_args());
  16. }
  17. }
  18. $a = new V8Js();
  19. $a->myobj = new Testing();
  20. $a->executeString("PHP.myobj.mytest('arg1', 'arg2');", "test1.js");
  21. $a->executeString("PHP.myobj.mytest(true, false, 1234567890);", "test2.js");
  22. $a->executeString("PHP.myobj.mytest(3.14, 42, null);", "test3.js");
  23. // Invalid parameters
  24. try {
  25. $a->executeString("PHP.myobj.mytest();", "test4.js");
  26. } catch (V8JsException $e) {
  27. echo $e->getMessage(), "\n";
  28. }
  29. try {
  30. $a->executeString("PHP.myobj.mytest('arg1', 'arg2', 'arg3', 'extra_arg');", "test5.js");
  31. } catch (V8JsException $e) {
  32. echo $e->getMessage(), "\n";
  33. }
  34. try {
  35. date_default_timezone_set("UTC");
  36. echo "\nTEST: Javascript Date -> PHP DateTime\n";
  37. echo "======================================\n";
  38. $a->executeString("date = new Date('September 8, 1975 09:00:00'); print(date + '\\n'); PHP.myobj.mytest(date, 'foo');", "test6.js");
  39. } catch (V8JsException $e) {
  40. echo $e->getMessage(), "\n";
  41. }
  42. // Array / Object
  43. try {
  44. $a->executeString("PHP.myobj.mytest(PHP.myobj, new Array(1,2,3), new Array('foo', 'bar', PHP.myobj));", "test7.js");
  45. } catch (V8JsException $e) {
  46. var_dump($e);
  47. }
  48. ?>
  49. ===EOF===
  50. --EXPECT--
  51. array(2) {
  52. [0]=>
  53. string(4) "arg1"
  54. [1]=>
  55. string(4) "arg2"
  56. }
  57. array(3) {
  58. [0]=>
  59. bool(true)
  60. [1]=>
  61. bool(false)
  62. [2]=>
  63. int(1234567890)
  64. }
  65. array(3) {
  66. [0]=>
  67. float(3.14)
  68. [1]=>
  69. int(42)
  70. [2]=>
  71. NULL
  72. }
  73. test4.js:1: TypeError: Testing::mytest() expects at least 2 parameters, 0 given
  74. array(4) {
  75. [0]=>
  76. string(4) "arg1"
  77. [1]=>
  78. string(4) "arg2"
  79. [2]=>
  80. string(4) "arg3"
  81. [3]=>
  82. string(9) "extra_arg"
  83. }
  84. TEST: Javascript Date -> PHP DateTime
  85. ======================================
  86. Mon Sep 08 1975 09:00:00 GMT+0200 (EET)
  87. array(2) {
  88. [0]=>
  89. object(DateTime)#4 (3) {
  90. ["date"]=>
  91. string(19) "1975-09-08 09:00:00"
  92. ["timezone_type"]=>
  93. int(1)
  94. ["timezone"]=>
  95. string(6) "+02:00"
  96. }
  97. [1]=>
  98. string(3) "foo"
  99. }
  100. array(3) {
  101. [0]=>
  102. object(V8Object)#4 (2) {
  103. ["mytest"]=>
  104. object(V8Function)#6 (0) {
  105. }
  106. ["foo"]=>
  107. string(8) "ORIGINAL"
  108. }
  109. [1]=>
  110. array(3) {
  111. [0]=>
  112. int(1)
  113. [1]=>
  114. int(2)
  115. [2]=>
  116. int(3)
  117. }
  118. [2]=>
  119. array(3) {
  120. [0]=>
  121. string(3) "foo"
  122. [1]=>
  123. string(3) "bar"
  124. [2]=>
  125. object(V8Object)#5 (2) {
  126. ["mytest"]=>
  127. object(V8Function)#6 (0) {
  128. }
  129. ["foo"]=>
  130. string(8) "ORIGINAL"
  131. }
  132. }
  133. }
  134. ===EOF===