dechex_variation1.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. --TEST--
  2. Test dechex() 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. /* Prototype : string dechex ( int $number )
  12. * Description: Returns a string containing a hexadecimal representation of the given number argument.
  13. * Source code: ext/standard/math.c
  14. */
  15. echo "*** Testing dechex() : usage variations ***\n";
  16. //get an unset variable
  17. $unset_var = 10;
  18. unset ($unset_var);
  19. // heredoc string
  20. $heredoc = <<<EOT
  21. abc
  22. xyz
  23. EOT;
  24. // get a class
  25. class classA
  26. {
  27. }
  28. // get a resource variable
  29. $fp = fopen(__FILE__, "r");
  30. $inputs = array(
  31. // int data
  32. /*1*/ 0,
  33. 1,
  34. 12345,
  35. -2345,
  36. 4294967295, // largest decimal
  37. 4294967296,
  38. // float data
  39. /*7*/ 10.5,
  40. -10.5,
  41. 12.3456789000e10,
  42. 12.3456789000E-10,
  43. .5,
  44. // null data
  45. /*12*/ NULL,
  46. null,
  47. // boolean data
  48. /*14*/ true,
  49. false,
  50. TRUE,
  51. FALSE,
  52. // empty data
  53. /*18*/ "",
  54. '',
  55. array(),
  56. // string data
  57. /*21*/ "abcxyz",
  58. 'abcxyz',
  59. $heredoc,
  60. // object data
  61. /*24*/ new classA(),
  62. // undefined data
  63. /*25*/ @$undefined_var,
  64. // unset data
  65. /*26*/ @$unset_var,
  66. // resource variable
  67. /*27*/ $fp
  68. );
  69. // loop through each element of $inputs to check the behaviour of dechex()
  70. $iterator = 1;
  71. foreach($inputs as $input) {
  72. echo "\n-- Iteration $iterator --\n";
  73. var_dump(dechex($input));
  74. $iterator++;
  75. };
  76. fclose($fp);
  77. ?>
  78. ===Done===
  79. --EXPECTF--
  80. *** Testing dechex() : usage variations ***
  81. -- Iteration 1 --
  82. string(1) "0"
  83. -- Iteration 2 --
  84. string(1) "1"
  85. -- Iteration 3 --
  86. string(4) "3039"
  87. -- Iteration 4 --
  88. string(8) "fffff6d7"
  89. -- Iteration 5 --
  90. string(8) "ffffffff"
  91. -- Iteration 6 --
  92. string(1) "0"
  93. -- Iteration 7 --
  94. string(1) "a"
  95. -- Iteration 8 --
  96. string(8) "fffffff6"
  97. -- Iteration 9 --
  98. string(8) "be991a08"
  99. -- Iteration 10 --
  100. string(1) "0"
  101. -- Iteration 11 --
  102. string(1) "0"
  103. -- Iteration 12 --
  104. string(1) "0"
  105. -- Iteration 13 --
  106. string(1) "0"
  107. -- Iteration 14 --
  108. string(1) "1"
  109. -- Iteration 15 --
  110. string(1) "0"
  111. -- Iteration 16 --
  112. string(1) "1"
  113. -- Iteration 17 --
  114. string(1) "0"
  115. -- Iteration 18 --
  116. string(1) "0"
  117. -- Iteration 19 --
  118. string(1) "0"
  119. -- Iteration 20 --
  120. string(1) "0"
  121. -- Iteration 21 --
  122. string(1) "0"
  123. -- Iteration 22 --
  124. string(1) "0"
  125. -- Iteration 23 --
  126. string(1) "0"
  127. -- Iteration 24 --
  128. Notice: Object of class classA could not be converted to int in %s on line %d
  129. string(1) "1"
  130. -- Iteration 25 --
  131. string(1) "0"
  132. -- Iteration 26 --
  133. string(1) "0"
  134. -- Iteration 27 --
  135. string(%d) "%s"
  136. ===Done===