var_dump.phpt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. --EXPECTF--
  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%r(\.0+)?%r"
  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 (18) {
  132. ["createFromFormat"] =>
  133. object(Closure)#%d {
  134. function () { [native code] }
  135. }
  136. ["getLastErrors"] =>
  137. object(Closure)#%d {
  138. function () { [native code] }
  139. }
  140. ["format"] =>
  141. object(Closure)#%d {
  142. function () { [native code] }
  143. }
  144. ["modify"] =>
  145. object(Closure)#%d {
  146. function () { [native code] }
  147. }
  148. ["add"] =>
  149. object(Closure)#%d {
  150. function () { [native code] }
  151. }
  152. ["sub"] =>
  153. object(Closure)#%d {
  154. function () { [native code] }
  155. }
  156. ["getTimezone"] =>
  157. object(Closure)#%d {
  158. function () { [native code] }
  159. }
  160. ["setTimezone"] =>
  161. object(Closure)#%d {
  162. function () { [native code] }
  163. }
  164. ["getOffset"] =>
  165. object(Closure)#%d {
  166. function () { [native code] }
  167. }
  168. ["setTime"] =>
  169. object(Closure)#%d {
  170. function () { [native code] }
  171. }
  172. ["setDate"] =>
  173. object(Closure)#%d {
  174. function () { [native code] }
  175. }
  176. ["setISODate"] =>
  177. object(Closure)#%d {
  178. function () { [native code] }
  179. }
  180. ["setTimestamp"] =>
  181. object(Closure)#%d {
  182. function () { [native code] }
  183. }
  184. ["getTimestamp"] =>
  185. object(Closure)#%d {
  186. function () { [native code] }
  187. }
  188. ["diff"] =>
  189. object(Closure)#%d {
  190. function () { [native code] }
  191. }
  192. ["$date"] =>
  193. string(%d) "1976-09-27 09:00:00%r(\.0+)?%r"
  194. ["$timezone_type"] =>
  195. int(3)
  196. ["$timezone"] =>
  197. string(3) "UTC"
  198. }
  199. ["array"] =>
  200. array(3) {
  201. [0] =>
  202. int(1)
  203. [1] =>
  204. int(2)
  205. [2] =>
  206. int(3)
  207. }
  208. ["object"] =>
  209. array (1) {
  210. ["field"] =>
  211. string(3) "foo"
  212. }
  213. ["function"] =>
  214. object(Closure)#%d (0) {
  215. }
  216. ["phpobject"] =>
  217. object(Foo)#%d (1) {
  218. ["$field"] =>
  219. string(3) "php"
  220. }
  221. }
  222. --- JS var_dump of JS object ----
  223. object(Object)#%d (12) {
  224. ["undefined"] =>
  225. NULL
  226. ["null"] =>
  227. NULL
  228. ["bool"] =>
  229. bool(true)
  230. ["string"] =>
  231. string(6) "string"
  232. ["uint"] =>
  233. int(1)
  234. ["int"] =>
  235. int(-1)
  236. ["number"] =>
  237. float(3.141593)
  238. ["regexp"] =>
  239. regexp(/regexp/)
  240. ["array"] =>
  241. array(3) {
  242. [0] =>
  243. int(1)
  244. [1] =>
  245. int(2)
  246. [2] =>
  247. int(3)
  248. }
  249. ["object"] =>
  250. object(Object)#%d (1) {
  251. ["field"] =>
  252. string(3) "foo"
  253. }
  254. ["function"] =>
  255. object(Closure)#%d {
  256. function id(x) { return x; }
  257. }
  258. ["phpobject"] =>
  259. object(Foo)#%d (1) {
  260. ["$field"] =>
  261. string(3) "php"
  262. }
  263. }
  264. --- PHP var_dump of JS object ----
  265. object(V8Object)#%d (12) {
  266. ["undefined"]=>
  267. NULL
  268. ["null"]=>
  269. NULL
  270. ["bool"]=>
  271. bool(true)
  272. ["string"]=>
  273. string(6) "string"
  274. ["uint"]=>
  275. int(1)
  276. ["int"]=>
  277. int(-1)
  278. ["number"]=>
  279. float(3.141592654)
  280. ["regexp"]=>
  281. object(V8Object)#%d (0) {
  282. }
  283. ["array"]=>
  284. array(3) {
  285. [0]=>
  286. int(1)
  287. [1]=>
  288. int(2)
  289. [2]=>
  290. int(3)
  291. }
  292. ["object"]=>
  293. object(V8Object)#%d (1) {
  294. ["field"]=>
  295. string(3) "foo"
  296. }
  297. ["function"]=>
  298. object(V8Function)#%d (0) {
  299. }
  300. ["phpobject"]=>
  301. object(Foo)#%d (1) {
  302. ["field"]=>
  303. string(3) "php"
  304. }
  305. }
  306. ===EOF===