vprintf_variation3.phpt 1.8 KB

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