Bug #54566 [Com]: bug into recursive function
| From: | paridin at paridin dot com | Date: | Tue, 19 Apr 2011 03:08:05 +0000 |
| Subject: | Bug #54566 [Com]: bug into recursive function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-160275@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54566&edit=1
ID: 54566
Comment by: paridin at paridin dot com
Reported by: paridin at paridin dot com
Summary: bug into recursive function
Status: Bogus
Type: Bug
Package: Output Control
Operating System: Linux,Windows
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2011-04-19 02:58:19] dtajchreber@php.net
return foo(++$i); instead of return foo($i++);
foo($i++); will always call foo(0);
------------------------------------------------------------------------
[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