I am moving some code (that I inherited) from PHP 5.4 to PHP 7.2. The following preg_replace_callback fails with preg_last_error of PREG_JIT_STACKLIMIT_ERROR, and returns an empty string. This happens when the subject string gets beyond a certain length:
$string = preg_replace_callback( "/\?>((.|\n)*?)<\?(php)?/","eval_mixed_helper",$string,-1,$count);
I found a few discussions on this. If I use ini_set('pcre.jit', false); the problem goes away, but I'm not sure that is the best solution.
I'm no regex expert by any means, so I wonder how the pattern in the preg_replace_callback could be improved to avoid this overflow. I think what it does is match any chunk of html between a php end tag and the next php start tag.
I also tried:
"/\?>((.)*?)<\?(php)?/s"
...which may get a little further but still fails.