vprintf_variation2.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. --TEST--
  2. Test vprintf() function : usage variations - unexpected values for args argument
  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 unexpected values are passed to
  11. * the '$args' arguments of the function
  12. */
  13. echo "*** Testing vprintf() : with unexpected values for args argument ***\n";
  14. // initialising the required variables
  15. $format = '%s';
  16. //get an unset variable
  17. $unset_var = 10;
  18. unset ($unset_var);
  19. // declaring a class
  20. class sample
  21. {
  22. public function __toString() {
  23. return "object";
  24. }
  25. }
  26. // Defining resource
  27. $file_handle = fopen(__FILE__, 'r');
  28. //array of values to iterate over
  29. $values = array(
  30. // int data
  31. /*1*/ 0,
  32. 1,
  33. 12345,
  34. -2345,
  35. // float data
  36. /*5*/ 10.5,
  37. -10.5,
  38. 10.1234567e10,
  39. 10.7654321E-10,
  40. .5,
  41. // null data
  42. /*10*/ NULL,
  43. null,
  44. // boolean data
  45. /*12*/ true,
  46. false,
  47. TRUE,
  48. FALSE,
  49. // empty data
  50. /*16*/ "",
  51. '',
  52. // string data
  53. /*18*/ "string",
  54. 'string',
  55. // object data
  56. /*20*/ new sample(),
  57. // undefined data
  58. /*21*/ @$undefined_var,
  59. // unset data
  60. /*22*/ @$unset_var,
  61. // resource data
  62. /*23*/ $file_handle
  63. );
  64. // loop through each element of the array for args
  65. $counter = 1;
  66. foreach($values as $value) {
  67. echo "\n-- Iteration $counter --\n";
  68. $result = vprintf($format,$value);
  69. echo "\n";
  70. var_dump($result);
  71. $counter++;
  72. };
  73. // closing the resource
  74. fclose($file_handle);
  75. ?>
  76. ===DONE===
  77. --EXPECTF--
  78. *** Testing vprintf() : with unexpected values for args argument ***
  79. -- Iteration 1 --
  80. 0
  81. int(1)
  82. -- Iteration 2 --
  83. 1
  84. int(1)
  85. -- Iteration 3 --
  86. 12345
  87. int(5)
  88. -- Iteration 4 --
  89. -2345
  90. int(5)
  91. -- Iteration 5 --
  92. 10.5
  93. int(4)
  94. -- Iteration 6 --
  95. -10.5
  96. int(5)
  97. -- Iteration 7 --
  98. 101234567000
  99. int(12)
  100. -- Iteration 8 --
  101. 1.07654321E-9
  102. int(13)
  103. -- Iteration 9 --
  104. 0.5
  105. int(3)
  106. -- Iteration 10 --
  107. Warning: vprintf(): Too few arguments in %s on line %d
  108. bool(false)
  109. -- Iteration 11 --
  110. Warning: vprintf(): Too few arguments in %s on line %d
  111. bool(false)
  112. -- Iteration 12 --
  113. 1
  114. int(1)
  115. -- Iteration 13 --
  116. int(0)
  117. -- Iteration 14 --
  118. 1
  119. int(1)
  120. -- Iteration 15 --
  121. int(0)
  122. -- Iteration 16 --
  123. int(0)
  124. -- Iteration 17 --
  125. int(0)
  126. -- Iteration 18 --
  127. string
  128. int(6)
  129. -- Iteration 19 --
  130. string
  131. int(6)
  132. -- Iteration 20 --
  133. Warning: vprintf(): Too few arguments in %s on line %d
  134. bool(false)
  135. -- Iteration 21 --
  136. Warning: vprintf(): Too few arguments in %s on line %d
  137. bool(false)
  138. -- Iteration 22 --
  139. Warning: vprintf(): Too few arguments in %s on line %d
  140. bool(false)
  141. -- Iteration 23 --
  142. Resource id #%d
  143. int(%d)
  144. ===DONE===