bindec_variation1.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. --TEST--
  2. Test bindec() function : usage variations - different data types as $binary_string arg
  3. --SKIPIF--
  4. <?php
  5. if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
  6. ?>
  7. --FILE--
  8. <?php
  9. /* Prototype : number bindec ( string $binary_string )
  10. * Description: Returns the decimal equivalent of the binary number represented by the binary_string argument.
  11. * Source code: ext/standard/math.c
  12. */
  13. echo "*** Testing bindec() : usage variations ***\n";
  14. //get an unset variable
  15. $unset_var = 10;
  16. unset ($unset_var);
  17. // heredoc string
  18. $heredoc = <<<EOT
  19. abc
  20. xyz
  21. EOT;
  22. // get a resource variable
  23. $fp = fopen(__FILE__, "r");
  24. $inputs = array(
  25. // int data
  26. /*1*/ 0,
  27. 1,
  28. 12345,
  29. -2345,
  30. // float data
  31. /*5*/ 10.5,
  32. -10.5,
  33. 12.3456789000e10,
  34. 12.3456789000E-10,
  35. .5,
  36. // null data
  37. /*10*/ NULL,
  38. null,
  39. // boolean data
  40. /*12*/ true,
  41. false,
  42. TRUE,
  43. FALSE,
  44. // empty data
  45. /*16*/ "",
  46. '',
  47. array(),
  48. // string data
  49. /*19*/ "abcxyz",
  50. 'abcxyz',
  51. $heredoc,
  52. // undefined data
  53. /*22*/ @$undefined_var,
  54. // unset data
  55. /*23*/ @$unset_var,
  56. // resource variable
  57. /*24*/ $fp
  58. );
  59. // loop through each element of $inputs to check the behaviour of bindec()
  60. $iterator = 1;
  61. foreach($inputs as $input) {
  62. echo "\n-- Iteration $iterator --\n";
  63. var_dump(bindec($input));
  64. $iterator++;
  65. };
  66. fclose($fp);
  67. ?>
  68. ===Done===
  69. --EXPECTF--
  70. *** Testing bindec() : usage variations ***
  71. -- Iteration 1 --
  72. int(0)
  73. -- Iteration 2 --
  74. int(1)
  75. -- Iteration 3 --
  76. int(1)
  77. -- Iteration 4 --
  78. int(0)
  79. -- Iteration 5 --
  80. int(2)
  81. -- Iteration 6 --
  82. int(2)
  83. -- Iteration 7 --
  84. int(8)
  85. -- Iteration 8 --
  86. int(1)
  87. -- Iteration 9 --
  88. int(0)
  89. -- Iteration 10 --
  90. int(0)
  91. -- Iteration 11 --
  92. int(0)
  93. -- Iteration 12 --
  94. int(1)
  95. -- Iteration 13 --
  96. int(0)
  97. -- Iteration 14 --
  98. int(1)
  99. -- Iteration 15 --
  100. int(0)
  101. -- Iteration 16 --
  102. int(0)
  103. -- Iteration 17 --
  104. int(0)
  105. -- Iteration 18 --
  106. Notice: Array to string conversion in %s on line %d
  107. int(0)
  108. -- Iteration 19 --
  109. int(0)
  110. -- Iteration 20 --
  111. int(0)
  112. -- Iteration 21 --
  113. int(0)
  114. -- Iteration 22 --
  115. int(0)
  116. -- Iteration 23 --
  117. int(0)
  118. -- Iteration 24 --
  119. int(%d)
  120. ===Done===