Why does PHP have preg_last_error() instead of just throwing an error ?
Some errors you can have from executing a regex through preg_replace()
are logged to PHP error file. Some others are silent and you have to check for their presence with preg_last_error()
. Why is that ?
For example, an invalid REGEX is gonna send a PHP Warning. But going over the preg JIT stack limit will not, and the only way to detect this error is by checking preg_last_error()
return value.
More information on the later error in this topic PHP PREG_JIT_STACKLIMIT_ERROR - inefficient regex