I was surprised when I just tried the following PHP code:
function foo()
{
foo();
}
foo();
I expected to get "500: Internal server error". Instead the connection was closed immediately (no bytes received), and the log files show that apache segfaulted. WTF? Is this a known bug in PHP? Are there some configuration options that I'm missing? Because a crashed process for every accidental stack overflow is, well... pretty unacceptable, I think.
PHP is not able to deal with this, it will just go into an infinite loop and produce a segmentation fault.
http://bugs.php.net/bug.php?id=49823
also
http://www.mail-archive.com/[email protected]/msg128905.html
avoid using recursive functions they are generally a bad idea" 0 riiight:))) they were invented because its a bad ideea:))...
I recomment setting a hrd upper-limit on the number of times the functions is called. DO NOT use global variables (you may actually need to call more recursive functions, why pollute the globals like this?). You may use extra parameters for a function
function a($param1, $param2, $depth=100){
$depth--;
if(!$depth==0) return error
}
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