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] [email protected]

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

Reply via email to