|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2004-06-15 17:03 UTC] felix at trilithium dot de
 Description:
------------
Apache eat all memory when your try the example code
Reproduce code:
---------------
class firstClass{
 	function __construct(){
		echo __CLASS__."::".__FUNCTION__."<br>";
	}
	function test(){
		echo __CLASS__."::".__FUNCTION__."<br>";
		return $this;
	}
 }
 class secondClass extends firstClass{
 	function __construct(){
                echo __CLASS__."::".__FUNCTION__."<br>"; 
		parent::$this->__construct(); //<-here Apache eat all memory
		//parent::$this->test(); // this works		
	}
 }
 
$e= new secondClass;
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 08:00:01 2025 UTC | 
$this->__construct() is a recursive call to secondClass' constructor. Since the constructor never returns, the recursion never bottoms out; it is effectively an infinite loop. Each call consumes space on the stack, so eventually PHP chews up all available memory and dies. You would see the same behaviour if secondClass' constructor was: function __construct() { $this->__construct(); } What you really want, as alex dot pagnoni at solarix dot it has pointed out is: function __construct() { parent::__construct(); }