PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

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