[php-src] PR #21906: ext/standard: improve explode() error message for empty separator

From: Date: Tue, 28 Apr 2026 23:55:23 +0000
Subject: [php-src] PR #21906: ext/standard: improve explode() error message for empty separator
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-35934@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/21906 Author: diegoasales This change improves the error message of explode() when an empty separator is provided. Currently, the error only states that the separator must not be empty, without offering guidance on how to achieve the likely intended behavior. A common mistake is attempting to split a string into individual characters using explode('', $string). In such cases, the intended behavior is character-based splitting. PHP already provides appropriate functions for this purpose, such as str_split() and mb_str_split(), but developers may not immediately recall them. This patch enhances the error message to suggest these alternatives: Before: explode(): Argument #1 ($separator) must not be empty After: explode(): Argument #1 ($separator) must not be empty. Use str_split() or mb_str_split() to split a string into characters This change: - does not affect behavior or error type (still ValueError) - only improves developer experience - updates existing tests accordingly

« previous php.git-pulls (#35934) next »