PageRenderTime 32ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/general_functions/var_dump.php

https://gitlab.com/iranjith4/hhvm
PHP | 284 lines | 221 code | 28 blank | 35 comment | 0 complexity | 2042b820f2ffed3b53c915d0dc61b198 MD5 | raw file
  1. <?php
  2. /* Prototype: void var_dump ( mixed $expression [, mixed $expression [, $...]] );
  3. Description: Displays structured information about one or more expressions that includes its type and value.
  4. */
  5. /* Prototype: void check_vardump( $variables );
  6. Description: use var_dump() to display the variables */
  7. function check_vardump( $variables ) {
  8. $counter = 1;
  9. foreach( $variables as $variable ) {
  10. echo "-- Iteration $counter --\n";
  11. var_dump($variable);
  12. $counter++;
  13. }
  14. }
  15. echo "\n*** Testing var_dump() on integer variables ***\n";
  16. $integers = array (
  17. 0, // zero as argument
  18. 000000123, //octal value of 83
  19. 123000000,
  20. -00000123, //octal value of 83
  21. -12300000,
  22. range(1,10), // positive values
  23. range(-1,-10), // negative values
  24. +2147483647, // max positive integer
  25. +2147483648, // max positive integer + 1
  26. -2147483648, // min range of integer
  27. -2147483647, // min range of integer + 1
  28. 0x7FFFFFFF, // max positive hexadecimal integer
  29. -0x80000000, // min range of hexadecimal integer
  30. 017777777777, // max posotive octal integer
  31. -020000000000 // min range of octal integer
  32. );
  33. /* calling check_vardump() to display contents of integer variables
  34. using var_dump() */
  35. check_vardump($integers);
  36. echo "\n*** Testing var_dump() on float variables ***\n";
  37. $floats = array (
  38. -0.0,
  39. +0.0,
  40. 1.234,
  41. -1.234,
  42. -2.000000,
  43. 000002.00,
  44. -.5,
  45. .567,
  46. -.6700000e-3,
  47. -.6700000E+3,
  48. .6700000E+3,
  49. .6700000e+3,
  50. -4.10003e-3,
  51. -4.10003E+3,
  52. 4.100003e-3,
  53. 4.100003E+3,
  54. 1e5,
  55. -1e5,
  56. 1e-5,
  57. -1e-5,
  58. 1e+5,
  59. -1e+5,
  60. 1E5,
  61. -1E5,
  62. 1E+5,
  63. -1E+5,
  64. 1E-5,
  65. -1E-5,
  66. -0x80000001, // float value, beyond max negative int
  67. 0x80000001, // float value, beyond max positive int
  68. 020000000001, // float value, beyond max positive int
  69. -020000000001 // float value, beyond max negative int
  70. );
  71. /* calling check_vardump() to display contents of float variables
  72. using var_dump() */
  73. check_vardump($floats);
  74. echo "\n*** Testing var_dump() on string variables ***\n";
  75. $strings = array (
  76. "",
  77. '',
  78. " ",
  79. ' ',
  80. "0",
  81. "\0",
  82. '\0',
  83. "\t",
  84. '\t',
  85. "PHP",
  86. 'PHP',
  87. "abcd\x0n1234\x0005678\x0000efgh\xijkl", // strings with hexadecimal NULL
  88. "abcd\0efgh\0ijkl\x00mnop\x000qrst\00uvwx\0000yz", // strings with octal NULL
  89. "1234\t\n5678\n\t9100\rabcda" // strings with escape characters
  90. );
  91. /* calling check_vardump() to display contents of strings
  92. using var_dump() */
  93. check_vardump($strings);
  94. echo "\n*** Testing var_dump() on boolean variables ***\n";
  95. $booleans = array (
  96. TRUE,
  97. FALSE,
  98. true,
  99. false
  100. );
  101. /* calling check_vardump() to display boolean variables
  102. using var_dump() */
  103. check_vardump($booleans);
  104. echo "\n*** Testing var_dump() on array variables ***\n";
  105. $arrays = array (
  106. array(),
  107. array(NULL),
  108. array(null),
  109. array(true),
  110. array(""),
  111. array(''),
  112. array(array(), array()),
  113. array(array(1, 2), array('a', 'b')),
  114. array(1 => 'One'),
  115. array("test" => "is_array"),
  116. array(0),
  117. array(-1),
  118. array(10.5, 5.6),
  119. array("string", "test"),
  120. array('string', 'test'),
  121. );
  122. /* calling check_vardump() to display contents of an array
  123. using var_dump() */
  124. check_vardump($arrays);
  125. echo "\n*** Testing var_dump() on object variables ***\n";
  126. class object_class
  127. {
  128. var $value;
  129. public $public_var1 = 10;
  130. private $private_var1 = 20;
  131. private $private_var2;
  132. protected $protected_var1 = "string_1";
  133. protected $protected_var2;
  134. function object_class ( ) {
  135. $this->value = 50;
  136. $this->public_var2 = 11;
  137. $this->private_var2 = 21;
  138. $this->protected_var2 = "string_2";
  139. }
  140. public function foo1() {
  141. echo "foo1() is called\n";
  142. }
  143. protected function foo2() {
  144. echo "foo2() is called\n";
  145. }
  146. private function foo3() {
  147. echo "foo3() is called\n";
  148. }
  149. }
  150. /* class with no member */
  151. class no_member_class {
  152. // no members
  153. }
  154. /* class with member as object of other class */
  155. class contains_object_class
  156. {
  157. var $p = 30;
  158. var $class_object1;
  159. public $class_object2;
  160. private $class_object3;
  161. protected $class_object4;
  162. var $no_member_class_object;
  163. public function func() {
  164. echo "func() is called \n";
  165. }
  166. function contains_object_class () {
  167. $this->class_object1 = new object_class();
  168. $this->class_object2 = new object_class();
  169. $this->class_object3 = $this->class_object1;
  170. $this->class_object4 = $this->class_object2;
  171. $this->no_member_class_object = new no_member_class();
  172. $this->class_object5 = $this; //recursive reference
  173. }
  174. }
  175. /* objects of different classes */
  176. $obj = new contains_object_class;
  177. $temp_class_obj = new object_class();
  178. /* object which is unset */
  179. $unset_obj = new object_class();
  180. unset($unset_obj);
  181. $objects = array (
  182. new object_class,
  183. new no_member_class,
  184. new contains_object_class,
  185. $obj,
  186. $obj->class_object1,
  187. $obj->class_object2,
  188. $obj->no_member_class_object,
  189. $temp_class_obj,
  190. @$unset_obj
  191. );
  192. /* calling check_vardump() to display contents of the objects
  193. using var_dump() */
  194. check_vardump($objects);
  195. echo "\n** Testing var_dump() on objects having circular reference **\n";
  196. $recursion_obj1 = new object_class();
  197. $recursion_obj2 = new object_class();
  198. $recursion_obj1->obj = &$recursion_obj2; //circular reference
  199. $recursion_obj2->obj = &$recursion_obj1; //circular reference
  200. var_dump($recursion_obj2);
  201. echo "\n*** Testing var_dump() on resources ***\n";
  202. /* file type resource */
  203. $file_handle = fopen(__FILE__, "r");
  204. /* directory type resource */
  205. $dir_handle = opendir( dirname(__FILE__) );
  206. $resources = array (
  207. $file_handle,
  208. $dir_handle
  209. );
  210. /* calling check_vardump() to display the resource content type
  211. using var_dump() */
  212. check_vardump($resources);
  213. echo "\n*** Testing var_dump() on different combinations of scalar
  214. and non-scalar variables ***\n";
  215. /* a variable which is unset */
  216. $unset_var = 10.5;
  217. unset($unset_var);
  218. /* unset file type resource */
  219. unset($file_handle);
  220. $variations = array (
  221. array( 123, -1.2345, "a" ),
  222. array( "d", array(1, 3, 5), true, null),
  223. array( new no_member_class, array(), false, 0 ),
  224. array( -0.00, "Where am I?", array(7,8,9), TRUE, 'A', 987654321 ),
  225. array( @$unset_var, 2.E+10, 100-20.9, 000004.599998 ), //unusual data
  226. array( "array(1,2,3,4)1.0000002TRUE", @$file_handle, 111333.00+45e5, '/00\7')
  227. );
  228. /* calling check_vardump() to display combinations of scalar and
  229. non-scalar variables using var_dump() */
  230. check_vardump($variations);
  231. echo "\n*** Testing var_dump() on miscelleneous input arguments ***\n";
  232. $misc_values = array (
  233. @$unset_var,
  234. NULL, // NULL argument
  235. @$undef_variable, //undefined variable
  236. null
  237. );
  238. /* calling check_vardump() to display miscelleneous data using var_dump() */
  239. check_vardump($misc_values);
  240. echo "\n*** Testing var_dump() on multiple arguments ***\n";
  241. var_dump( $integers, $floats, $strings, $arrays, $booleans, $resources,
  242. $objects, $misc_values, $variations );
  243. /* checking var_dump() on functions */
  244. echo "\n*** Testing var_dump() on anonymous functions ***\n";
  245. $newfunc = create_function('$a,$b', 'return "$a * $b = " . ($a * $b);');
  246. echo "New anonymous function: $newfunc\n";
  247. var_dump( $newfunc(2, 3) );
  248. /* creating anonymous function dynamically */
  249. var_dump( create_function('$a', 'return "$a * $a = " . ($a * $b);') );
  250. echo "\n*** Testing error conditions ***\n";
  251. //passing zero argument
  252. var_dump();
  253. /* closing resource handle used */
  254. closedir($dir_handle);
  255. echo "Done\n";
  256. ?>