object_method_call.phpt 2.9 KB

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