|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43187 Recursive loop crashes php instead of emitting error
Submitted: 2007-11-04 20:06 UTC Modified: 2007-11-06 20:27 UTC
From: thuejk at gmail dot com Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.2.4 OS: Linux
Private report: No CVE-ID: None
 [2007-11-04 20:06 UTC] thuejk at gmail dot com
When running a recursive loop with lots of iterations, PHP will segfault.

This will usually be a problem when you write buggy code by accident, but I guess it is possible to imagine sane programs which uses lots of recursive calls.

In any case, it is somewhat hard to debug the crash when it happens, because you do not get an error message when running it in a browser.

Reproduce code:

function f() {
  global $i;
  printf("%d\n", $i++);


Expected result:
(Ignoring the fact that the posted function is tail recursive, and therefore could be rewritten as a non-recursive loop)

PHP should emit an E_ERROR before it runs out of space. Preferably also an E_RECOVERABLE_ERROR or E_WARNING a little before it really runs out of space.

Actual result:
$ php test.php
zsh: segmentation fault  php test.php


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-06 20:27 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is a known recursion limit.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 07:01:29 2024 UTC