PageRenderTime 41ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 109 lines | 72 code | 15 blank | 22 comment | 0 complexity | 52267a64dc9e34f408caa8d2c29cec1c 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 is_array ( mixed $var );
  3. * Description: Finds whether the given variable is an array
  4. */
  5. echo "*** Testing is_array() on different type of arrays ***\n";
  6. /* different types of arrays */
  7. $arrays = array(
  8. array(),
  9. array(NULL),
  10. array(null),
  11. array(true),
  12. array(""),
  13. array(''),
  14. array(array(), array()),
  15. array(array(1, 2), array('a', 'b')),
  16. array(1 => 'One'),
  17. array("test" => "is_array"),
  18. array(0),
  19. array(-1),
  20. array(10.5, 5.6),
  21. array("string", "test"),
  22. array('string', 'test')
  23. );
  24. /* loop to check that is_array() recognizes different
  25. type of arrays, expected output bool(true) */
  26. $loop_counter = 1;
  27. foreach ($arrays as $var_array ) {
  28. echo "-- Iteration $loop_counter --\n"; $loop_counter++;
  29. var_dump( is_array ($var_array) );
  30. }
  31. echo "\n*** Testing is_array() on non array types ***\n";
  32. // get a resource type variable
  33. $fp = fopen (__FILE__, "r");
  34. $dfp = opendir ( dirname(__FILE__) );
  35. // unset variables
  36. $unset_array = array(10);
  37. unset($unset_array);
  38. // other types in a array
  39. $varient_arrays = array (
  40. /* integers */
  41. 543915,
  42. -5322,
  43. 0x55F,
  44. -0xCCF,
  45. 123,
  46. -0654,
  47. /* strings */
  48. "",
  49. '',
  50. "0",
  51. '0',
  52. 'string',
  53. "string",
  54. /* floats */
  55. 10.0000000000000000005,
  56. .5e6,
  57. -.5E7,
  58. .5E+8,
  59. -.5e+90,
  60. 1e5,
  61. /* objects */
  62. new stdclass,
  63. /* resources */
  64. $fp,
  65. $dfp,
  66. /* nulls */
  67. null,
  68. NULL,
  69. /* boolean */
  70. true,
  71. TRUE,
  72. FALSE,
  73. false,
  74. /* unset/undefined arrays */
  75. @$unset_array,
  76. @$undefined_array
  77. );
  78. /* loop through the $varient_array to see working of
  79. is_array() on non array types, expected output bool(false) */
  80. $loop_counter = 1;
  81. foreach ($varient_arrays as $type ) {
  82. echo "-- Iteration $loop_counter --\n"; $loop_counter++;
  83. var_dump( is_array ($type) );
  84. }
  85. echo "\n*** Testing error conditions ***\n";
  86. //Zero argument
  87. var_dump( is_array() );
  88. //arguments more than expected
  89. var_dump( is_array ($fp, $fp) );
  90. echo "Done\n";
  91. /* close resources */
  92. fclose($fp);
  93. closedir($dfp);
  94. ?>