Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

str_split() Throws ValueError With Negative Lengths

str_split() used to emit a warning and return false, when provided with $length, the second 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.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat