Edit report at http://bugs.php.net/bug.php?id=54566&edit=1
ID: 54566 Updated by: [email protected] Reported by: paridin at paridin dot com Summary: bug into recursive function -Status: Open +Status: Bogus Type: Bug Package: Output Control Operating System: Linux,Windows PHP Version: Irrelevant Block user comment: N Private report: N New Comment: return foo(++$i); instead of return foo($i++); foo($i++); will always call foo(0); Previous Comments: ------------------------------------------------------------------------ [2011-04-19 02:10:49] paridin at paridin dot com Description: ------------ When you try to make recursive function and send the counter directly. you have an error, to fix this, you need increment before the counter, and after send this counter. Test script: --------------- <?php function foo($i){ if( $i < 100){ echo " ".$i; return foo($i++); // bug }else{ return $m="\r\nEnd Process"; } } $i=0; echo foo($i); ?> Expected result: ---------------- 1 2 3 4 5 6 7 8 ... 97 98 99 100 End Process Actual result: -------------- 00000...0000000 Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in /home/paridin/public_html/bug.php on line 5 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54566&edit=1
