2

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.

S. Arquet
  • 29
  • 4
  • `(.|\n)*?` causes it. Replace with `(?s:.*?)`. Or `"/\?>(.*?)<\?(php)?/s"` – Wiktor Stribiżew Mar 28 '19 at 21:29
  • Thank you! The first one doesn't seem to work (generates an error) but the second one does. – S. Arquet Mar 29 '19 at 00:25
  • I would also say that this question is different from the linked one, in that I was specifically asking for help with this specific regex, and the other question, while related to the same issue, does not provide a specific solution to this question. – S. Arquet Apr 01 '19 at 00:20

0 Answers0