PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

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