TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.6 KiB
110 lines
2.6 KiB
--TEST--
|
|
Test array_sum() function : usage variations - 'input' array with unexpected values as array element
|
|
--SKIPIF--
|
|
<?php
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
/*
|
|
* Testing array_sum() with array having other than numeric entries
|
|
* strings, bool, null, subarrays & objects
|
|
*/
|
|
|
|
class MyClass
|
|
{
|
|
public $value;
|
|
public function __construct($value)
|
|
{
|
|
$this->value = $value;
|
|
}
|
|
}
|
|
|
|
function main() {
|
|
echo "*** Testing array_sum() : array with unexpected entries ***\n";
|
|
|
|
// string array
|
|
$input = array('Apple', 'Banana', 'Carrot', 'Mango', 'Orange');
|
|
echo "-- array with string values --\n";
|
|
var_dump( array_sum($input) );
|
|
|
|
// bool array
|
|
$input = array( true, true, false, true, false);
|
|
echo "-- array with bool values --\n";
|
|
var_dump( array_sum($input) );
|
|
|
|
// array with null entry
|
|
$input = array(null, NULL);
|
|
echo "-- array with null values --\n";
|
|
var_dump( array_sum($input) );
|
|
|
|
// array with subarray
|
|
$input = array(
|
|
array(1, 2),
|
|
array(),
|
|
array(0)
|
|
);
|
|
echo "-- array with subarrays --\n";
|
|
var_dump( array_sum($input) );
|
|
|
|
// array of objects
|
|
$input = array(
|
|
new MyClass(2),
|
|
new MyClass(5),
|
|
new MyClass(10),
|
|
new MyClass(0)
|
|
);
|
|
echo "-- array with object values --\n";
|
|
var_dump( array_sum($input) );
|
|
|
|
// Mixed values
|
|
$input = array( 5, -8, 7.2, -1.2, "10", "apple", 'Mango', true, false, null, NULL, array( array(1,2), array(0), array()));
|
|
echo "-- array with mixed values --\n";
|
|
var_dump( array_sum($input) );
|
|
echo "Done";
|
|
}
|
|
?>
|
|
--EXPECTF--
|
|
*** Testing array_sum() : array with unexpected entries ***
|
|
-- array with string values --
|
|
|
|
%s: Addition is not supported on type string in %s on line %d
|
|
|
|
%s: Addition is not supported on type string in %s on line %d
|
|
|
|
%s: Addition is not supported on type string in %s on line %d
|
|
|
|
%s: Addition is not supported on type string in %s on line %d
|
|
|
|
%s: Addition is not supported on type string in %s on line %d
|
|
int(0)
|
|
-- array with bool values --
|
|
int(3)
|
|
-- array with null values --
|
|
int(0)
|
|
-- array with subarrays --
|
|
|
|
%s: Addition is not supported on type array in %s on line %d
|
|
|
|
%s: Addition is not supported on type array in %s on line %d
|
|
|
|
%s: Addition is not supported on type array in %s on line %d
|
|
int(0)
|
|
-- array with object values --
|
|
|
|
%s: Addition is not supported on type MyClass in %s on line %d
|
|
|
|
%s: Addition is not supported on type MyClass in %s on line %d
|
|
|
|
%s: Addition is not supported on type MyClass in %s on line %d
|
|
|
|
%s: Addition is not supported on type MyClass in %s on line %d
|
|
int(0)
|
|
-- array with mixed values --
|
|
|
|
%s: Addition is not supported on type string in %s on line %d
|
|
|
|
%s: Addition is not supported on type string in %s on line %d
|
|
|
|
%s: Addition is not supported on type array in %s on line %d
|
|
float(14)
|
|
Done
|
|
|