dechex_variation1.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --TEST--
  2. Test dechex() function : usage variations - different data types as $num 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 dechex() : usage variations ***\n";
  12. $inputs = [
  13. // int data
  14. /*1*/ 0,
  15. 1,
  16. 12345,
  17. -2345,
  18. 4294967295, // largest decimal
  19. 4294967296,
  20. // float data
  21. /* 7*/ 12.3456789000e10,
  22. // boolean data
  23. /* 8*/ true,
  24. false,
  25. TRUE,
  26. FALSE,
  27. // empty data
  28. /*12*/ "",
  29. '',
  30. ];
  31. // loop through each element of $inputs to check the behaviour of dechex()
  32. foreach ($inputs as $i => $input) {
  33. $iterator = $i + 1;
  34. echo "\n-- Iteration $iterator --\n";
  35. try {
  36. var_dump(dechex($input));
  37. } catch (TypeError $exception) {
  38. echo $exception->getMessage() . "\n";
  39. }
  40. }
  41. ?>
  42. --EXPECT--
  43. *** Testing dechex() : usage variations ***
  44. -- Iteration 1 --
  45. string(1) "0"
  46. -- Iteration 2 --
  47. string(1) "1"
  48. -- Iteration 3 --
  49. string(4) "3039"
  50. -- Iteration 4 --
  51. string(8) "fffff6d7"
  52. -- Iteration 5 --
  53. dechex(): Argument #1 ($num) must be of type int, float given
  54. -- Iteration 6 --
  55. dechex(): Argument #1 ($num) must be of type int, float given
  56. -- Iteration 7 --
  57. dechex(): Argument #1 ($num) must be of type int, float given
  58. -- Iteration 8 --
  59. string(1) "1"
  60. -- Iteration 9 --
  61. string(1) "0"
  62. -- Iteration 10 --
  63. string(1) "1"
  64. -- Iteration 11 --
  65. string(1) "0"
  66. -- Iteration 12 --
  67. dechex(): Argument #1 ($num) must be of type int, string given
  68. -- Iteration 13 --
  69. dechex(): Argument #1 ($num) must be of type int, string given