vprintf_variation8.phpt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. --TEST--
  2. Test vprintf() function : usage variations - string formats with non-string values
  3. --FILE--
  4. <?php
  5. /*
  6. * Test vprintf() when different string formats and non-string values are passed to
  7. * the '$format' and '$args' arguments of the function
  8. */
  9. echo "*** Testing vprintf() : string formats and non-string values ***\n";
  10. // defining array of string formats
  11. $formats =
  12. '%s %+s %-s
  13. %ls %4s %-4s
  14. %10.4s %-10.4s %04s %04.4s
  15. %\'#2s %\'2s %\'$2s %\'_2s
  16. %3$s %4$s %1$s %2$s';
  17. // Arrays of non string values for the format defined in $format.
  18. // Each sub array contains non string values which correspond to each format in $format
  19. $args_array = array(
  20. // array of float values
  21. array(2.2, .2, 10.2,
  22. 123456.234, -1234.6789, +1234.6789,
  23. 2.1234567e10, +2.7654321e10, -2.7654321e10,
  24. 12345.780, 12.000000011111, -12.00000111111, -123456.234,
  25. 3.33, +4.44, 1.11,-2.22 ),
  26. // array of int values
  27. array(2, -2, +2,
  28. 123456, -12346789, +12346789,
  29. 123200, +20000, -40000, 22212,
  30. 12345780, 1211111, -12111111, -12345634,
  31. 3, +4, 1,-2 ),
  32. // different arrays
  33. array( array(0), array(1, 2), array(-1, -1),
  34. array("123"), array('-123'), array("-123"),
  35. array(true), array(false), array(TRUE), array(FALSE),
  36. array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
  37. array("3"), array("4"), array("1"), array("2") ),
  38. // array of boolean data
  39. array( true, TRUE, false,
  40. TRUE, FALSE, 1,
  41. true, false, TRUE, FALSE,
  42. 0, 1, 1, 0,
  43. 1, TRUE, 0, FALSE),
  44. );
  45. // looping to test vprintf() with different string formats from the above $format array
  46. // and with non-string values from the above $args_array array
  47. $counter = 1;
  48. foreach($args_array as $args) {
  49. echo "\n-- Iteration $counter --\n";
  50. $result = vprintf($formats, $args);
  51. echo "\n";
  52. var_dump($result);
  53. $counter++;
  54. }
  55. ?>
  56. --EXPECTF--
  57. *** Testing vprintf() : string formats and non-string values ***
  58. -- Iteration 1 --
  59. 2.2 0.2 10.2
  60. 123456.234 -1234.6789 1234.6789
  61. 2123 2765 -27654321000 1234
  62. 12.000000011111 -12.00000111111 -123456.234 3.33
  63. 10.2 123456.234 2.2 0.2
  64. int(173)
  65. -- Iteration 2 --
  66. 2 -2 2
  67. 123456 -12346789 12346789
  68. 1232 2000 -40000 2221
  69. 12345780 1211111 -12111111 -12345634
  70. 2 123456 2 -2
  71. int(133)
  72. -- Iteration 3 --
  73. Warning: Array to string conversion in %s on line %d
  74. Warning: Array to string conversion in %s on line %d
  75. Warning: Array to string conversion in %s on line %d
  76. Warning: Array to string conversion in %s on line %d
  77. Warning: Array to string conversion in %s on line %d
  78. Warning: Array to string conversion in %s on line %d
  79. Warning: Array to string conversion in %s on line %d
  80. Warning: Array to string conversion in %s on line %d
  81. Warning: Array to string conversion in %s on line %d
  82. Warning: Array to string conversion in %s on line %d
  83. Warning: Array to string conversion in %s on line %d
  84. Warning: Array to string conversion in %s on line %d
  85. Warning: Array to string conversion in %s on line %d
  86. Warning: Array to string conversion in %s on line %d
  87. Warning: Array to string conversion in %s on line %d
  88. Warning: Array to string conversion in %s on line %d
  89. Warning: Array to string conversion in %s on line %d
  90. Warning: Array to string conversion in %s on line %d
  91. Array Array Array
  92. Array Array Array
  93. Arra Arra Array Arra
  94. Array Array Array Array
  95. Array Array Array Array
  96. int(132)
  97. -- Iteration 4 --
  98. 1 1
  99. 1 1
  100. 1 0001 0000
  101. #0 1 $1 _0
  102. 1 1 1
  103. int(82)