1--TEST--
2Test 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/*
11* Passing different scalar/nonscalar values as 'input' argument to array_sum()
12*/
13
14echo "*** Testing array_sum() : unexpected values for 'input' ***\n";
15
16// get an unset variable
17$unset_var = 10;
18unset ($unset_var);
19
20// Class definition
21class MyClass
22{
23  public function __toString()
24  {
25    return "object";
26  }
27}
28
29// different scalar/non scalar values for 'input' argument
30$input_values = array(
31
32         // int data
33/*1*/    0,
34         1,
35         12345,
36         -2345,
37
38         // float data
39/*5*/    10.5,
40         -10.5,
41         10.1234567e8,
42         10.7654321E-8,
43         .5,
44
45         // null data
46/*10*/   NULL,
47         null,
48
49         // boolean data
50/*12*/   true,
51         false,
52         TRUE,
53         FALSE,
54
55         // empty data
56/*16*/   "",
57         '',
58
59         // string data
60/*18*/   "string",
61         'string',
62
63         // object data
64/*20*/   new MyClass(),
65
66         // resource data
67/*21*/   $fp = fopen(__FILE__,'r'),
68
69         // undefined data
70/*22*/   @$undefined_var,
71
72         // unset data
73/*23*/   @$unset_var,
74);
75
76// loop through each element of the array for input
77for($count = 0; $count < count($input_values); $count++) {
78  echo "-- Iteration ".($count + 1)." --\n";
79  var_dump( array_sum($input_values[$count]) );
80};
81
82fclose($fp);
83echo "Done"
84?>
85--EXPECTF--
86*** Testing array_sum() : unexpected values for 'input' ***
87-- Iteration 1 --
88
89Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d
90NULL
91-- Iteration 2 --
92
93Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d
94NULL
95-- Iteration 3 --
96
97Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d
98NULL
99-- Iteration 4 --
100
101Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d
102NULL
103-- Iteration 5 --
104
105Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d
106NULL
107-- Iteration 6 --
108
109Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d
110NULL
111-- Iteration 7 --
112
113Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d
114NULL
115-- Iteration 8 --
116
117Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d
118NULL
119-- Iteration 9 --
120
121Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d
122NULL
123-- Iteration 10 --
124
125Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d
126NULL
127-- Iteration 11 --
128
129Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d
130NULL
131-- Iteration 12 --
132
133Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d
134NULL
135-- Iteration 13 --
136
137Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d
138NULL
139-- Iteration 14 --
140
141Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d
142NULL
143-- Iteration 15 --
144
145Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d
146NULL
147-- Iteration 16 --
148
149Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d
150NULL
151-- Iteration 17 --
152
153Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d
154NULL
155-- Iteration 18 --
156
157Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d
158NULL
159-- Iteration 19 --
160
161Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d
162NULL
163-- Iteration 20 --
164
165Warning: array_sum() expects parameter 1 to be array, object given in %s on line %d
166NULL
167-- Iteration 21 --
168
169Warning: array_sum() expects parameter 1 to be array, resource given in %s on line %d
170NULL
171-- Iteration 22 --
172
173Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d
174NULL
175-- Iteration 23 --
176
177Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d
178NULL
179Done
180