bindec_variation1.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. echo "*** Testing bindec() : usage variations ***\n";
  10. // heredoc string
  11. $heredoc = <<<EOT
  12. abc
  13. xyz
  14. EOT;
  15. // get a resource variable
  16. $fp = fopen(__FILE__, "r");
  17. $inputs = array(
  18. // int data
  19. /*1*/ 0,
  20. 1,
  21. 12345,
  22. -2345,
  23. // float data
  24. /*5*/ 10.5,
  25. -10.5,
  26. 12.3456789000e10,
  27. 12.3456789000E-10,
  28. .5,
  29. // boolean data
  30. /*12*/ true,
  31. false,
  32. TRUE,
  33. FALSE,
  34. // empty data
  35. /*16*/ "",
  36. '',
  37. array(),
  38. // string data
  39. /*19*/ "abcxyz",
  40. 'abcxyz',
  41. $heredoc,
  42. // resource variable
  43. /*24*/ $fp
  44. );
  45. // loop through each element of $inputs to check the behaviour of bindec()
  46. $iterator = 1;
  47. foreach($inputs as $input) {
  48. echo "\n-- Iteration $iterator --\n";
  49. try {
  50. var_dump(bindec($input));
  51. } catch (TypeError $e) {
  52. echo $e->getMessage(), "\n";
  53. }
  54. $iterator++;
  55. };
  56. fclose($fp);
  57. ?>
  58. --EXPECTF--
  59. *** Testing bindec() : usage variations ***
  60. -- Iteration 1 --
  61. int(0)
  62. -- Iteration 2 --
  63. int(1)
  64. -- Iteration 3 --
  65. Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
  66. int(1)
  67. -- Iteration 4 --
  68. Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
  69. int(0)
  70. -- Iteration 5 --
  71. Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
  72. int(2)
  73. -- Iteration 6 --
  74. Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
  75. int(2)
  76. -- Iteration 7 --
  77. Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
  78. int(8)
  79. -- Iteration 8 --
  80. Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
  81. int(1)
  82. -- Iteration 9 --
  83. Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
  84. int(0)
  85. -- Iteration 10 --
  86. int(1)
  87. -- Iteration 11 --
  88. int(0)
  89. -- Iteration 12 --
  90. int(1)
  91. -- Iteration 13 --
  92. int(0)
  93. -- Iteration 14 --
  94. int(0)
  95. -- Iteration 15 --
  96. int(0)
  97. -- Iteration 16 --
  98. bindec(): Argument #1 ($binary_string) must be of type string, array given
  99. -- Iteration 17 --
  100. Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
  101. int(0)
  102. -- Iteration 18 --
  103. Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
  104. int(0)
  105. -- Iteration 19 --
  106. Deprecated: Invalid characters passed for attempted conversion, these have been ignored in %s on line %d
  107. int(0)
  108. -- Iteration 20 --
  109. bindec(): Argument #1 ($binary_string) must be of type string, resource given