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

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

http://github.com/facebook/hiphop-php
PHP | 145 lines | 108 code | 16 blank | 21 comment | 0 complexity | 47bfb71605ffa18098906eaf0749f333 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_int ( mixed $var );
  3. * Description: Finds whether the given variable is an integer
  4. */
  5. echo "*** Testing is_int(), is_integer() & is_long() with valid integer values ***\n";
  6. // different valid integer vlaues
  7. $valid_ints = array(
  8. 0,
  9. 1,
  10. -1,
  11. -2147483648, // max negative integer value
  12. -2147483647,
  13. 2147483647, // max positive integer value
  14. 2147483640,
  15. 0x123B, // integer as hexadecimal
  16. 0x12ab,
  17. 0Xfff,
  18. 0XFA,
  19. -0x80000000, // max negative integer as hexadecimal
  20. 0x7fffffff, // max postive integer as hexadecimal
  21. 0x7FFFFFFF, // max postive integer as hexadecimal
  22. 0123, // integer as octal
  23. 01912, // should be quivalent to octal 1
  24. -020000000000, // max negative integer as octal
  25. 017777777777, // max positive integer as octal
  26. );
  27. /* loop to check that is_int() recognizes different
  28. integer values, expected output: bool(true) */
  29. $loop_counter = 1;
  30. foreach ($valid_ints as $int_val ) {
  31. echo "--Iteration $loop_counter--\n"; $loop_counter++;
  32. var_dump( is_int($int_val) );
  33. var_dump( is_integer($int_val) );
  34. var_dump( is_long($int_val) );
  35. }
  36. echo "\n*** Testing is_int(), is_integer() & is_long() with non integer values ***\n";
  37. // resource type variable
  38. $fp = fopen (__FILE__, "r");
  39. $dfp = opendir ( dirname(__FILE__) );
  40. // unset variable
  41. $unset_var = 10;
  42. unset ($unset_var);
  43. // other types in a array
  44. $not_int_types = array (
  45. /* float values */
  46. -2147483649, // float value
  47. 2147483648, // float value
  48. -0x80000001, // float value, beyond max negative int
  49. 0x800000001, // float value, beyond max positive int
  50. 020000000001, // float value, beyond max positive int
  51. -020000000001, // float value, beyond max negative int
  52. 0.0,
  53. -0.1,
  54. 1.0,
  55. 1e5,
  56. -1e6,
  57. 1E8,
  58. -1E9,
  59. 10.0000000000000000005,
  60. 10.5e+5,
  61. /* objects */
  62. new stdclass,
  63. /* resources */
  64. $fp,
  65. $dfp,
  66. /* arrays */
  67. array(),
  68. array(0),
  69. array(1),
  70. array(NULL),
  71. array(null),
  72. array("string"),
  73. array(true),
  74. array(TRUE),
  75. array(false),
  76. array(FALSE),
  77. array(1,2,3,4),
  78. array(1 => "One", "two" => 2),
  79. /* strings */
  80. "",
  81. '',
  82. "0",
  83. '0',
  84. "1",
  85. '1',
  86. "\x01",
  87. '\x01',
  88. "\01",
  89. '\01',
  90. 'string',
  91. "string",
  92. "true",
  93. "FALSE",
  94. 'false',
  95. 'TRUE',
  96. "NULL",
  97. 'null',
  98. /* booleans */
  99. true,
  100. false,
  101. TRUE,
  102. FALSE,
  103. /* undefined and unset vars */
  104. @$unset_var,
  105. @$undefined_var
  106. );
  107. /* loop through the $not_int_types to see working of
  108. is_int() on non integer types, expected output: bool(false) */
  109. $loop_counter = 1;
  110. foreach ($not_int_types as $type ) {
  111. echo "--Iteration $loop_counter--\n"; $loop_counter++;
  112. var_dump( is_int($type) );
  113. var_dump( is_integer($type) );
  114. var_dump( is_long($type) );
  115. }
  116. echo "\n*** Testing error conditions ***\n";
  117. //Zero argument
  118. var_dump( is_int() );
  119. var_dump( is_integer() );
  120. var_dump( is_long() );
  121. //arguments more than expected
  122. var_dump( is_int(TRUE, FALSE) );
  123. var_dump( is_integer(TRUE, FALSE) );
  124. var_dump( is_long(TRUE, FALSE) );
  125. echo "Done\n";
  126. // close the resources
  127. fclose($fp);
  128. closedir($dfp);
  129. ?>