str_split() Throws ValueError With Negative Lengths¶
str_split() used to emit a warning and return false, when provided with length (2nd argument) as an integer less then 1. In PHP 8.0, it now throws a ValueError.
PHP code¶
<?php
str_split('abc', 0);
?>
Before¶
Warning: str_split(): The length of each segment must be greater than zero
After¶
Fatal error: Uncaught ValueError: str_split(): Argument #2 ($length) must be greater than 0
PHP version change¶
This behavior changed in 8.0