Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...