array_sum() Checks Operands More Thoroughly¶
array_sum() used to cast the arguments to integers before executing the additions. Nowadays, the strange types raise a warning, as illustrated here with the array.
PHP code¶
<?php
print array_sum([1, false, []]);
?>
Before¶
1
After¶
PHP Warning: array_sum(): Addition is not supported on type array in /codes/arraySumChecks.php on line 3
Warning: array_sum(): Addition is not supported on type array in /codes/arraySumChecks.php on line 3
1
PHP version change¶
This behavior changed in 8.3