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

preg_grep() Returns false On A PCRE Execution Error

preg_grep() filters an array using a regular expression. Until PHP 8.6, when the underlying PCRE engine failed on one of the array’s entries (for example malformed UTF-8 input combined with the /u modifier), that entry was silently skipped and a partial array was returned for the rest. In PHP 8.6, preg_grep() returns false as soon as a PCRE execution error occurs, matching the behavior of the other preg_* functions.

PHP code

<?php

$arr = ["\xC3\x28", 'valid'];
var_dump(preg_grep('/./u', $arr));

?>

Before

array(0) {
}

After

bool(false)

PHP version change

This behavior changed in 8.6.

See Also

Extension

© 2023-2026, Damien Seguy - Exakat