php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35159 big variable value in recursive function crashes
Submitted: 2005-11-08 20:14 UTC Modified: 2005-11-10 00:22 UTC
From: pekka at photography-on-the dot net Assigned: dmitry (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS, 4.4.1 (2005-11-08) (cvs) OS: *
Private report: No CVE-ID: None
 [2005-11-08 20:14 UTC] pekka at photography-on-the dot net
Description:
------------
Weird recursive issue with 4.4.1

function test_recursive ($count=0) {
	$count++;
	if ($count >= 50) {
		print "done";
		return;
	}
	test_recursive ($count);
}

test_recursive();

works, but when $count is larger than 197 it crashes (Apache gives error 500)


in PHP 5.0.4 this works ok with any $count



Reproduce code:
---------------
function test_recursive ($count=0) {
	$count++;
	if ($count >= 500) {
		print "done";
		return;
	}
	test_recursive ($count);
}

test_recursive();

Expected result:
----------------
done

Actual result:
--------------
Server: page not found (error 500), php crash.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-08 20:27 UTC] sniper@php.net
I can reproduce this with latest CVS of 5.1, using 35701 as the limit. Dmitry, any ideas?
 [2005-11-08 21:06 UTC] pekka at photography-on-the dot net
correction: 5.0.4 is not free of this, in php 5.0.4 the limit is 1291 on same machine.
 [2005-11-08 21:21 UTC] support at zend dot com
4.3.11, 4.4.0 also affected, but with different limits...
 [2005-11-09 08:24 UTC] dmitry@php.net
Crash occurs becaose of program stack overflow. All PHP versions are affected.
 [2005-11-09 11:12 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Known issue, not a bug...
 [2005-11-09 14:27 UTC] pekka at photography-on-the dot net
That is surprising, such a simple example crashes PHP! I would be very interested to learn if there is a workaround, when you need to recurse very large data sets?
 [2005-11-10 00:22 UTC] nlopess@php.net
Currently you should avoid too deep recursion in PHP.
We need (and Java also) to implement the Tail Call optimization, as can be seen in Lisp or Scheme. This allows to recurse without using the stack for some cases.
This is one of the things I would like to do in the near future.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 23:01:26 2024 UTC