Warning: preg_match(): Internal pcre_fullinfo()

邮差的信 提交于 2019-12-17 19:33:18

问题


I have the following working code:

$test = '123456';

$int = preg_match('/^\d+$/', $test, $matches);

print_r(array($int, $matches));

However when I execute it on codepad I get the error:

Warning: preg_match(): Internal pcre_fullinfo() error -3 on line 5

But the code is running on my own machine (and the code should be fine IMHO).

I need to distribute my code in the future so it would be bad if it would break depending on some config. So what is the reason codepad breaks on it?


回答1:


Code executed via codepad is running in a very restricted environment:

Code execution is handled by a supervisor based on geordi. The strategy is to run everything under ptrace, with many system calls disallowed or ignored. Compilers and final executables are both executed in a chroot jail, with strict resource limits. The supervisor is written in Haskell.

While it's nothing you'd expect to break a regex engine it's very possible that the pcre library uses something internally that is blocked by the codepad environment. No production system uses such severe restrictions so you should be safe to use that code in your application.

The error code stands for "PCRE_ERROR_BADOPTION - the value of what was invalid". However, the code in the PHP source where the error occurs is rc = pcre_fullinfo(pce->re, extra, PCRE_INFO_CAPTURECOUNT, &num_subpats); which uses a constant for what. So it clearly means that the pcre library is broken on codepad.

If you wanted to be completely safe, you could write a small C program using libpcre to call that function on the same regex.



来源:https://stackoverflow.com/questions/8859363/warning-preg-match-internal-pcre-fullinfo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!