array_sum_variation1.phpt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. --TEST--
  2. Test array_sum() function : usage variations - unexpected values for 'input' argument
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed array_sum(array $input)
  6. * Description: Returns the sum of the array entries
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Passing different scalar/nonscalar values as 'input' argument to array_sum()
  11. */
  12. echo "*** Testing array_sum() : unexpected values for 'input' ***\n";
  13. // get an unset variable
  14. $unset_var = 10;
  15. unset ($unset_var);
  16. // Class definition
  17. class MyClass
  18. {
  19. public function __toString()
  20. {
  21. return "object";
  22. }
  23. }
  24. // different scalar/non scalar values for 'input' argument
  25. $input_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.1234567e8,
  35. 10.7654321E-8,
  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 MyClass(),
  53. // resource data
  54. /*21*/ $fp = fopen(__FILE__,'r'),
  55. // undefined data
  56. /*22*/ @$undefined_var,
  57. // unset data
  58. /*23*/ @$unset_var,
  59. );
  60. // loop through each element of the array for input
  61. for($count = 0; $count < count($input_values); $count++) {
  62. echo "-- Iteration ".($count + 1)." --\n";
  63. var_dump( array_sum($input_values[$count]) );
  64. };
  65. fclose($fp);
  66. echo "Done"
  67. ?>
  68. --EXPECTF--
  69. *** Testing array_sum() : unexpected values for 'input' ***
  70. -- Iteration 1 --
  71. Warning: array_sum() expects parameter 1 to be array, int given in %s on line %d
  72. NULL
  73. -- Iteration 2 --
  74. Warning: array_sum() expects parameter 1 to be array, int given in %s on line %d
  75. NULL
  76. -- Iteration 3 --
  77. Warning: array_sum() expects parameter 1 to be array, int given in %s on line %d
  78. NULL
  79. -- Iteration 4 --
  80. Warning: array_sum() expects parameter 1 to be array, int given in %s on line %d
  81. NULL
  82. -- Iteration 5 --
  83. Warning: array_sum() expects parameter 1 to be array, float given in %s on line %d
  84. NULL
  85. -- Iteration 6 --
  86. Warning: array_sum() expects parameter 1 to be array, float given in %s on line %d
  87. NULL
  88. -- Iteration 7 --
  89. Warning: array_sum() expects parameter 1 to be array, float given in %s on line %d
  90. NULL
  91. -- Iteration 8 --
  92. Warning: array_sum() expects parameter 1 to be array, float given in %s on line %d
  93. NULL
  94. -- Iteration 9 --
  95. Warning: array_sum() expects parameter 1 to be array, float given in %s on line %d
  96. NULL
  97. -- Iteration 10 --
  98. Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d
  99. NULL
  100. -- Iteration 11 --
  101. Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d
  102. NULL
  103. -- Iteration 12 --
  104. Warning: array_sum() expects parameter 1 to be array, bool given in %s on line %d
  105. NULL
  106. -- Iteration 13 --
  107. Warning: array_sum() expects parameter 1 to be array, bool given in %s on line %d
  108. NULL
  109. -- Iteration 14 --
  110. Warning: array_sum() expects parameter 1 to be array, bool given in %s on line %d
  111. NULL
  112. -- Iteration 15 --
  113. Warning: array_sum() expects parameter 1 to be array, bool given in %s on line %d
  114. NULL
  115. -- Iteration 16 --
  116. Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d
  117. NULL
  118. -- Iteration 17 --
  119. Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d
  120. NULL
  121. -- Iteration 18 --
  122. Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d
  123. NULL
  124. -- Iteration 19 --
  125. Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d
  126. NULL
  127. -- Iteration 20 --
  128. Warning: array_sum() expects parameter 1 to be array, object given in %s on line %d
  129. NULL
  130. -- Iteration 21 --
  131. Warning: array_sum() expects parameter 1 to be array, resource given in %s on line %d
  132. NULL
  133. -- Iteration 22 --
  134. Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d
  135. NULL
  136. -- Iteration 23 --
  137. Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d
  138. NULL
  139. Done