vprintf_variation10.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. --TEST--
  2. Test vprintf() function : usage variations - char formats with non-char 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 char formats and non-char values are passed to
  11. * the '$format' and '$args' arguments of the function
  12. */
  13. echo "*** Testing vprintf() : char formats and non-char values ***\n";
  14. // defining an array of various char formats
  15. $formats =
  16. '%c %+c %-c
  17. %lc %4c %-4c
  18. %10.4c %-10.4c %04c %04.4c
  19. %\'10c %\'10c %\'$10c %\'_10c
  20. %3$c %4$c %1$c %2$c';
  21. // Arrays of non char values for the format defined in $format.
  22. // Each sub array contains non char values which correspond to each format in $format
  23. $args_array = array(
  24. // array of float values
  25. array(65.8, -65.8, +66.8,
  26. 93.2, 126.8, -126.49,
  27. 35.44, -35.68, 32.99, -32.00,
  28. -61.51, 61.51, 50.49, -54.50,
  29. 83.33, +84.44, 81.11, 82.22),
  30. // array of int values
  31. array(65, -65, +66,
  32. 169, 126, -126,
  33. 35, -35, 32, -32,
  34. -61, 61, 50, -54,
  35. 83, +84, 81, 82),
  36. // array of strings
  37. array(" ", ' ', 'hello',
  38. '123hello', '-123hello', '+123hello',
  39. "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
  40. "1234hello", "hello\0world", "NULL", "true",
  41. "3", "4", '1', '2'),
  42. // different arrays
  43. array( array(0), array(1, 2), array(-1, -1),
  44. array("123"), array('-123'), array("-123"),
  45. array(true), array(false), array(TRUE), array(FALSE),
  46. array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
  47. array("3"), array("4"), array("1"), array("2") ),
  48. // array of boolean data
  49. array( true, TRUE, false,
  50. TRUE, FALSE, 1,
  51. true, false, TRUE, FALSE,
  52. 0, 1, 1, 0,
  53. 1, TRUE, 0, FALSE),
  54. );
  55. // looping to test vprintf() with different char formats from the above $format array
  56. // and with non-char values from the above $args_array array
  57. $counter = 1;
  58. foreach($args_array as $args) {
  59. echo "\n-- Iteration $counter --\n";
  60. $result = vprintf($formats, $args);
  61. echo "\n";
  62. var_dump($result);
  63. $counter++;
  64. }
  65. ?>
  66. --EXPECTF--
  67. *** Testing vprintf() : char formats and non-char values ***
  68. -- Iteration 1 --
  69. A ¿ B
  70. ] ~ ‚
  71. # Ý à
  72. Ã = 2 Ê
  73. B ] A ¿
  74. int(47)
  75. -- Iteration 2 --
  76. A ¿ B
  77. © ~ ‚
  78. # Ý à
  79. Ã = 2 Ê
  80. B © A ¿
  81. int(47)
  82. -- Iteration 3 --
  83. %0 %0 %0
  84. { … {
  85. %0 %0 @ %0
  86. Ò %0 %0 %0
  87. %0 { %0 %0
  88. int(47)
  89. -- Iteration 4 --
  90.   
  91.   
  92.    
  93.    
  94.    
  95. int(47)
  96. -- Iteration 5 --
  97.   %0
  98.  %0 
  99.  %0  %0
  100. %0   %0
  101. %0   
  102. int(47)