PageRenderTime 25ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 140 lines | 101 code | 17 blank | 22 comment | 0 complexity | 4b52df0ea785f05bc128a96cee490bdf 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_bool ( mixed $var );
  3. * Description: Finds whether the given variable is a boolean
  4. */
  5. echo "*** Testing is_bool() with valid boolean values ***\n";
  6. // different valid boolean vlaues
  7. $valid_bools = array(
  8. TRUE,
  9. FALSE,
  10. true,
  11. false,
  12. );
  13. /* loop to check that is_bool() recognizes different
  14. bool values, expected output: bool(true) */
  15. $loop_counter = 1;
  16. foreach ($valid_bools as $bool_val ) {
  17. echo "-- Iteration $loop_counter --\n"; $loop_counter++;
  18. var_dump( is_bool($bool_val) );
  19. }
  20. echo "\n*** Testing is_bool() on non boolean values ***\n";
  21. // get a resource type variable
  22. $fp = fopen (__FILE__, "r");
  23. $dfp = opendir ( dirname(__FILE__) );
  24. // unset variable
  25. $unset_bool1 = true;
  26. $unset_bool2 = false;
  27. $unset_var = 0;
  28. unset ($unset_bool1);
  29. unset ($unset_bool2);
  30. unset ($unset_var);
  31. // other types in a array
  32. $not_bool_types = array (
  33. /* integers */
  34. 0,
  35. 1,
  36. -1,
  37. -0,
  38. 543915,
  39. -5322,
  40. 0x0,
  41. 0x1,
  42. 0x55F,
  43. -0xCCF,
  44. 0123,
  45. -0654,
  46. 00,
  47. 01,
  48. /* strings */
  49. "",
  50. '',
  51. "0",
  52. '0',
  53. "1",
  54. '1',
  55. 'string',
  56. "string",
  57. "true",
  58. "false",
  59. "FALSE",
  60. "TRUE",
  61. 'true',
  62. 'false',
  63. 'FALSE',
  64. 'TRUE',
  65. "NULL",
  66. "null",
  67. /* floats */
  68. 0.0,
  69. 1.0,
  70. -1.0,
  71. 10.0000000000000000005,
  72. .5e6,
  73. -.5E7,
  74. .5E+8,
  75. -.5e+90,
  76. 1e5,
  77. -1e5,
  78. 1E5,
  79. -1E7,
  80. /* objects */
  81. new stdclass,
  82. /* resources */
  83. $fp,
  84. $dfp,
  85. /* nulls */
  86. null,
  87. NULL,
  88. /* arrays */
  89. array(),
  90. array(0),
  91. array(1),
  92. array(NULL),
  93. array(null),
  94. array("string"),
  95. array(true),
  96. array(TRUE),
  97. array(false),
  98. array(FALSE),
  99. array(1,2,3,4),
  100. array(1 => "One", "two" => 2),
  101. /* unset bool vars and undefined var */
  102. @$unset_bool1,
  103. @$unset_bool2,
  104. @$unset_var,
  105. @$undefined_var
  106. );
  107. /* loop through the $not_bool_types to see working of
  108. is_bool() on non bull types, expected output: bool(false) */
  109. $loop_counter = 1;
  110. foreach ($not_bool_types as $type ) {
  111. echo "-- Iteration $loop_counter --\n"; $loop_counter++;
  112. var_dump( is_bool($type) );
  113. }
  114. echo "\n*** Testing error conditions ***\n";
  115. //Zero argument
  116. var_dump( is_bool() );
  117. //arguments more than expected
  118. var_dump( is_bool(TRUE, FALSE) );
  119. echo "Done\n";
  120. // close resources
  121. fclose($fp);
  122. closedir($dfp);
  123. ?>