Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

php - Warning: preg_match(): Internal pcre_fullinfo()

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...