1--TEST--
2Test array_sum() function : usage variations - 'input' array with unexpected values as array element
3--FILE--
4<?php
5/*
6* Testing array_sum() with array having other than numeric entries
7*    strings, bool, null, subarrays & objects
8*/
9
10echo "*** Testing array_sum() : array with unexpected entries ***\n";
11
12// string array
13$input = array('Apple', 'Banana', 'Carrot', 'Mango', 'Orange');
14echo "-- array with string values --\n";
15var_dump( array_sum($input) );
16
17// bool array
18$input = array( true, true, false, true, false);
19echo "-- array with bool values --\n";
20var_dump( array_sum($input) );
21
22// array with null entry
23$input = array(null, NULL);
24echo "-- array with null values --\n";
25var_dump( array_sum($input) );
26
27// array with subarray
28$input = array(
29  array(1, 2),
30  array(),
31  array(0)
32);
33echo "-- array with subarrays --\n";
34var_dump( array_sum($input) );
35
36class MyClass
37{
38  public $value;
39  public function __construct($value)
40  {
41    $this->value = $value;
42  }
43}
44// array of objects
45$input = array(
46  new MyClass(2),
47  new MyClass(5),
48  new MyClass(10),
49  new MyClass(0)
50);
51echo "-- array with object values --\n";
52var_dump( array_sum($input) );
53
54// Mixed values
55$input = array( 5, -8, 7.2, -1.2, "10", "apple", 'Mango', true, false, null, NULL, array( array(1,2), array(0), array()));
56echo "-- array with mixed values --\n";
57var_dump( array_sum($input) );
58echo "Done"
59?>
60--EXPECTF--
61*** Testing array_sum() : array with unexpected entries ***
62-- array with string values --
63
64Warning: array_sum(): Addition is not supported on type string in %s on line %d
65
66Warning: array_sum(): Addition is not supported on type string in %s on line %d
67
68Warning: array_sum(): Addition is not supported on type string in %s on line %d
69
70Warning: array_sum(): Addition is not supported on type string in %s on line %d
71
72Warning: array_sum(): Addition is not supported on type string in %s on line %d
73int(0)
74-- array with bool values --
75int(3)
76-- array with null values --
77int(0)
78-- array with subarrays --
79
80Warning: array_sum(): Addition is not supported on type array in %s on line %d
81
82Warning: array_sum(): Addition is not supported on type array in %s on line %d
83
84Warning: array_sum(): Addition is not supported on type array in %s on line %d
85int(0)
86-- array with object values --
87
88Warning: array_sum(): Addition is not supported on type MyClass in %s on line %d
89
90Warning: array_sum(): Addition is not supported on type MyClass in %s on line %d
91
92Warning: array_sum(): Addition is not supported on type MyClass in %s on line %d
93
94Warning: array_sum(): Addition is not supported on type MyClass in %s on line %d
95int(0)
96-- array with mixed values --
97
98Warning: array_sum(): Addition is not supported on type string in %s on line %d
99
100Warning: array_sum(): Addition is not supported on type string in %s on line %d
101
102Warning: array_sum(): Addition is not supported on type array in %s on line %d
103float(14)
104Done
105