var_dump.phpt 6.6 KB

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