vprintf_variation2.phpt 3.7 KB

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