vprintf_variation3.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --TEST--
  2. Test vprintf() function : usage variations - int formats with int values
  3. --FILE--
  4. <?php
  5. /*
  6. * Test vprintf() when different int formats and int values are passed to
  7. * the '$format' and '$args' arguments of the function
  8. */
  9. echo "*** Testing vprintf() : int formats with int values ***\n";
  10. // defining array of int formats
  11. $formats = array(
  12. "%d",
  13. "%+d %-d",
  14. "%ld %4d %-4d",
  15. "%10.4d %-10.4d %04d %04.4d",
  16. "%'#2d %'2d %'$2d %'_2d",
  17. "%d %d %d %d",
  18. "% %%d",
  19. '%3$d %4$d %1$d %2$d'
  20. );
  21. // Arrays of int values for the format defined in $format.
  22. // Each sub array contains int values which correspond to each format string in $format
  23. $args_array = array(
  24. array(0),
  25. array(-1, 1),
  26. array(2147483647, +2147483640, -2147483640),
  27. array(123456, 12345678, -1234567, 1234567),
  28. array(111, 2222, 333333, 44444444),
  29. array(0x123b, 0xfAb, 0123, 012),
  30. array(1234, -5678),
  31. array(3, 4, 1, 2)
  32. );
  33. // looping to test vprintf() with different int formats from the above $format array
  34. // and with int values from the above $args_array array
  35. $counter = 1;
  36. foreach($formats as $format) {
  37. echo "\n-- Iteration $counter --\n";
  38. $result = vprintf($format, $args_array[$counter-1]);
  39. echo "\n";
  40. var_dump($result);
  41. $counter++;
  42. }
  43. ?>
  44. --EXPECT--
  45. *** Testing vprintf() : int formats with int values ***
  46. -- Iteration 1 --
  47. 0
  48. int(1)
  49. -- Iteration 2 --
  50. -1 1
  51. int(4)
  52. -- Iteration 3 --
  53. 2147483647 2147483640 -2147483640
  54. int(33)
  55. -- Iteration 4 --
  56. 123456 12345678 -1234567 1234567
  57. int(38)
  58. -- Iteration 5 --
  59. 111 2222 333333 44444444
  60. int(24)
  61. -- Iteration 6 --
  62. 4667 4011 83 10
  63. int(15)
  64. -- Iteration 7 --
  65. %-5678
  66. int(6)
  67. -- Iteration 8 --
  68. 1 2 3 4
  69. int(7)