|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54566 bug into recursive function
Submitted: 2011-04-19 02:10 UTC Modified: 2011-04-19 02:58 UTC
From: paridin at paridin dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: Irrelevant OS: Linux,Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: paridin at paridin dot com
New email:
PHP Version: OS:


 [2011-04-19 02:10 UTC] paridin at paridin dot com
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:
function foo($i){
if( $i < 100){
   echo " ".$i;
   return foo($i++); // bug
  return $m="\r\nEnd Process";
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


fix_recursive_function (last revision 2011-04-19 00:21 UTC by paridin at paridin dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-19 02:58 UTC]
-Status: Open +Status: Bogus
 [2011-04-19 02:58 UTC]
return foo(++$i); instead of return foo($i++);

foo($i++); will always call foo(0);
 [2011-04-19 05:08 UTC] paridin at paridin dot com
Yes, dtajchreber, this behavior is very rarely 'cause into python work well, but 
into C or PHP not run, i tested this same example into this three languages but, 
maybe Python support the bad logic, and i thinking i have a bad logic when i try 
send a counter while increment this.

thanks for the fast answer.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 30 19:01:32 2024 UTC