hexdec_variation1.phpt 2.8 KB

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