1--TEST--
2Test array_sum() function : usage variations - 'input' array with unexpected values as array element
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* Testing array_sum() with array having other than numeric entries
12*    strings, bool, null, subarrays & objects
13*/
14
15echo "*** Testing array_sum() : array with unexpected entries ***\n";
16
17// empty array
18$input = array();
19echo "-- empty array --\n";
20var_dump( array_sum($input) );
21
22// string array
23$input = array('Apple', 'Banana', 'Carrot', 'Mango', 'Orange');
24echo "-- array with string values --\n";
25var_dump( array_sum($input) );
26
27// bool array
28$input = array( true, true, false, true, false);
29echo "-- array with bool values --\n";
30var_dump( array_sum($input) );
31
32// array with null entry
33$input = array(null, NULL);
34echo "-- array with null values --\n";
35var_dump( array_sum($input) );
36
37// array with subarray
38$input = array(
39  array(1, 2),
40  array(),
41  array(0)
42);
43echo "-- array with subarrays --\n";
44var_dump( array_sum($input) );
45
46class MyClass
47{
48  public $value;
49  public function __construct($value)
50  {
51    $this->value = $value;
52  }
53}
54// array of objects
55$input = array(
56  new MyClass(2),
57  new MyClass(5),
58  new MyClass(10),
59  new MyClass(0)
60);
61echo "-- array with object values --\n";
62var_dump( array_sum($input) );
63
64// Mixed values
65$input = array( 5, -8, 7.2, -1.2, "10", "apple", 'Mango', true, false, null, NULL, array( array(1,2), array(0), array()));
66echo "-- array with mixed values --\n";
67var_dump( array_sum($input) );
68echo "Done"
69?>
70--EXPECT--
71*** Testing array_sum() : array with unexpected entries ***
72-- empty array --
73int(0)
74-- array with string values --
75int(0)
76-- array with bool values --
77int(3)
78-- array with null values --
79int(0)
80-- array with subarrays --
81int(0)
82-- array with object values --
83int(0)
84-- array with mixed values --
85float(14)
86Done
87