var_dump_73.phpt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. --TEST--
  2. Test V8::executeString() : var_dump
  3. --SKIPIF--
  4. <?php
  5. require_once(dirname(__FILE__) . '/skipif.inc');
  6. if (PHP_VERSION_ID < 70300) die('skip Only for php version >= 7.3');
  7. ?>
  8. --INI--
  9. date.timezone=UTC
  10. --FILE--
  11. <?php
  12. # Test var_dump of various types
  13. $JS = <<< EOT
  14. print("--- JS var_dump of PHP object ----\\n");
  15. var_dump(PHP.phptypes);
  16. print("--- JS var_dump of JS object ----\\n");
  17. var types = {
  18. undefined: undefined,
  19. null: null,
  20. bool: true,
  21. string: "string",
  22. uint: 1,
  23. int: -1,
  24. number: 3.141592654,
  25. // XXX this gets parsed with local timezone,
  26. // which is bad for test repeatability.
  27. //date: new Date('September 27, 1976 09:00:00 GMT'),
  28. regexp: /regexp/,
  29. array: [1,2,3],
  30. object: { field: "foo" },
  31. function: function id(x) { return x; },
  32. phpobject: PHP.obj
  33. };
  34. var_dump(types);
  35. print("--- PHP var_dump of JS object ----\\n");
  36. types;
  37. EOT;
  38. class Foo {
  39. var $field = "php";
  40. }
  41. $v8 = new V8Js();
  42. $v8->obj = new Foo;
  43. $phptypes = $v8->phptypes = array(
  44. "null" => NULL,
  45. "bool" => true,
  46. "string" => "string",
  47. "uint" => 1,
  48. "int" => -1,
  49. "number" => 3.141592654,
  50. "date" => new DateTime('September 27, 1976 09:00:00 UTC', new DateTimeZone('UTC')),
  51. //"regexp" => new Regexp('/regexp/'), /* no native PHP regex type */
  52. "array" => array(1,2,3),
  53. "object" => array( "field" => "foo" ),
  54. "function" => (function ($x) { return $x; }),
  55. "phpobject" => new Foo
  56. );
  57. echo "---- PHP var_dump of PHP object ----\n";
  58. var_dump($phptypes);
  59. try {
  60. var_dump($v8->executeString($JS, 'var_dump.js'));
  61. } catch (V8JsScriptException $e) {
  62. echo "Error!\n";
  63. var_dump($e);
  64. }
  65. ?>
  66. ===EOF===
  67. --EXPECTF--
  68. ---- PHP var_dump of PHP object ----
  69. array(11) {
  70. ["null"]=>
  71. NULL
  72. ["bool"]=>
  73. bool(true)
  74. ["string"]=>
  75. string(6) "string"
  76. ["uint"]=>
  77. int(1)
  78. ["int"]=>
  79. int(-1)
  80. ["number"]=>
  81. float(3.141592654)
  82. ["date"]=>
  83. object(DateTime)#%d (3) {
  84. ["date"]=>
  85. string(%d) "1976-09-27 09:00:00%r(\.0+)?%r"
  86. ["timezone_type"]=>
  87. int(3)
  88. ["timezone"]=>
  89. string(3) "UTC"
  90. }
  91. ["array"]=>
  92. array(3) {
  93. [0]=>
  94. int(1)
  95. [1]=>
  96. int(2)
  97. [2]=>
  98. int(3)
  99. }
  100. ["object"]=>
  101. array(1) {
  102. ["field"]=>
  103. string(3) "foo"
  104. }
  105. ["function"]=>
  106. object(Closure)#%d (1) {
  107. ["parameter"]=>
  108. array(1) {
  109. ["$x"]=>
  110. string(10) "<required>"
  111. }
  112. }
  113. ["phpobject"]=>
  114. object(Foo)#%d (1) {
  115. ["field"]=>
  116. string(3) "php"
  117. }
  118. }
  119. --- JS var_dump of PHP object ----
  120. array (11) {
  121. ["null"] =>
  122. NULL
  123. ["bool"] =>
  124. bool(true)
  125. ["string"] =>
  126. string(6) "string"
  127. ["uint"] =>
  128. int(1)
  129. ["int"] =>
  130. int(-1)
  131. ["number"] =>
  132. float(3.141593)
  133. ["date"] =>
  134. object(DateTime)#%d (19) {
  135. ["createFromImmutable"] =>
  136. object(Closure)#%d {
  137. function () { [native code] }
  138. }
  139. ["createFromFormat"] =>
  140. object(Closure)#%d {
  141. function () { [native code] }
  142. }
  143. ["getLastErrors"] =>
  144. object(Closure)#%d {
  145. function () { [native code] }
  146. }
  147. ["format"] =>
  148. object(Closure)#%d {
  149. function () { [native code] }
  150. }
  151. ["modify"] =>
  152. object(Closure)#%d {
  153. function () { [native code] }
  154. }
  155. ["add"] =>
  156. object(Closure)#%d {
  157. function () { [native code] }
  158. }
  159. ["sub"] =>
  160. object(Closure)#%d {
  161. function () { [native code] }
  162. }
  163. ["getTimezone"] =>
  164. object(Closure)#%d {
  165. function () { [native code] }
  166. }
  167. ["setTimezone"] =>
  168. object(Closure)#%d {
  169. function () { [native code] }
  170. }
  171. ["getOffset"] =>
  172. object(Closure)#%d {
  173. function () { [native code] }
  174. }
  175. ["setTime"] =>
  176. object(Closure)#%d {
  177. function () { [native code] }
  178. }
  179. ["setDate"] =>
  180. object(Closure)#%d {
  181. function () { [native code] }
  182. }
  183. ["setISODate"] =>
  184. object(Closure)#%d {
  185. function () { [native code] }
  186. }
  187. ["setTimestamp"] =>
  188. object(Closure)#%d {
  189. function () { [native code] }
  190. }
  191. ["getTimestamp"] =>
  192. object(Closure)#%d {
  193. function () { [native code] }
  194. }
  195. ["diff"] =>
  196. object(Closure)#%d {
  197. function () { [native code] }
  198. }
  199. ["$date"] =>
  200. string(%d) "1976-09-27 09:00:00%r(\.0+)?%r"
  201. ["$timezone_type"] =>
  202. int(3)
  203. ["$timezone"] =>
  204. string(3) "UTC"
  205. }
  206. ["array"] =>
  207. array(3) {
  208. [0] =>
  209. int(1)
  210. [1] =>
  211. int(2)
  212. [2] =>
  213. int(3)
  214. }
  215. ["object"] =>
  216. array (1) {
  217. ["field"] =>
  218. string(3) "foo"
  219. }
  220. ["function"] =>
  221. object(Closure)#%d (0) {
  222. }
  223. ["phpobject"] =>
  224. object(Foo)#%d (1) {
  225. ["$field"] =>
  226. string(3) "php"
  227. }
  228. }
  229. --- JS var_dump of JS object ----
  230. object(Object)#%d (12) {
  231. ["undefined"] =>
  232. NULL
  233. ["null"] =>
  234. NULL
  235. ["bool"] =>
  236. bool(true)
  237. ["string"] =>
  238. string(6) "string"
  239. ["uint"] =>
  240. int(1)
  241. ["int"] =>
  242. int(-1)
  243. ["number"] =>
  244. float(3.141593)
  245. ["regexp"] =>
  246. regexp(/regexp/)
  247. ["array"] =>
  248. array(3) {
  249. [0] =>
  250. int(1)
  251. [1] =>
  252. int(2)
  253. [2] =>
  254. int(3)
  255. }
  256. ["object"] =>
  257. object(Object)#%d (1) {
  258. ["field"] =>
  259. string(3) "foo"
  260. }
  261. ["function"] =>
  262. object(Closure)#%d {
  263. function id(x) { return x; }
  264. }
  265. ["phpobject"] =>
  266. object(Foo)#%d (1) {
  267. ["$field"] =>
  268. string(3) "php"
  269. }
  270. }
  271. --- PHP var_dump of JS object ----
  272. object(V8Object)#%d (12) {
  273. ["undefined"]=>
  274. NULL
  275. ["null"]=>
  276. NULL
  277. ["bool"]=>
  278. bool(true)
  279. ["string"]=>
  280. string(6) "string"
  281. ["uint"]=>
  282. int(1)
  283. ["int"]=>
  284. int(-1)
  285. ["number"]=>
  286. float(3.141592654)
  287. ["regexp"]=>
  288. object(V8Object)#%d (0) {
  289. }
  290. ["array"]=>
  291. array(3) {
  292. [0]=>
  293. int(1)
  294. [1]=>
  295. int(2)
  296. [2]=>
  297. int(3)
  298. }
  299. ["object"]=>
  300. object(V8Object)#%d (1) {
  301. ["field"]=>
  302. string(3) "foo"
  303. }
  304. ["function"]=>
  305. object(V8Function)#%d (0) {
  306. }
  307. ["phpobject"]=>
  308. object(Foo)#%d (1) {
  309. ["field"]=>
  310. string(3) "php"
  311. }
  312. }
  313. ===EOF===