php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: paridin at paridin dot com
New email:
PHP Version: OS:

 

 [2011-04-19 02:10 UTC] 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

Patches

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

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-19 02:58 UTC] dtajchreber@php.net
-Status: Open +Status: Bogus
 [2011-04-19 02:58 UTC] dtajchreber@php.net
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: Tue Apr 23 09:01:27 2024 UTC