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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With