mirror of
https://github.com/php/php-src.git
synced 2026-03-24 16:22:37 +01:00
RFC: https://wiki.php.net/rfc/saner-array-sum-product Moreover, the internal fast_add_function() function was removed.
24 lines
563 B
PHP
24 lines
563 B
PHP
--TEST--
|
|
Test array_sum() function: resources in array
|
|
--FILE--
|
|
<?php
|
|
$input = [10, STDERR /* Should get casted to 3 as an integer */];
|
|
|
|
echo "array_sum() version:\n";
|
|
var_dump(array_sum($input));
|
|
|
|
echo "array_reduce() version:\n";
|
|
try {
|
|
var_dump(array_reduce($input, fn($carry, $value) => $carry + $value, 0));
|
|
} catch (TypeError $e) {
|
|
echo $e->getMessage();
|
|
}
|
|
?>
|
|
--EXPECTF--
|
|
array_sum() version:
|
|
|
|
Warning: array_sum(): Addition is not supported on type resource in %s on line %d
|
|
int(13)
|
|
array_reduce() version:
|
|
Unsupported operand types: int + resource
|