php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28796 Apache eat all Memory (parent::$this->__construct())
Submitted: 2004-06-15 17:03 UTC Modified: 2004-09-16 01:00 UTC
Votes:4
Avg. Score:4.2 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: felix at trilithium dot de Assigned:
Status: No Feedback Package: Apache related
PHP Version: 5.0.0RC3 OS: Linux version 2.4.21-199-default
Private report: No CVE-ID: None
 [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;


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-17 13:38 UTC] alex dot pagnoni at solarix dot it
is parent::$this->__construct() the correct syntax? Wasn't 
it supposed to be parent::__construct()?
 [2004-06-18 17:41 UTC] benjcarson at digitaljunkies dot ca
$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();
}
 [2004-09-08 05:41 UTC] curt@php.net
parent::$this->__construct makes no sense, are you sure you didn't mean parent parent::__construct()


 [2004-09-16 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2004-10-05 03:25 UTC] derrickbtan dot lists at gmail dot com
Shouldn't this invalid syntax be caught @ compile/run time?  I ran into the same mistake when my IDE added $this-> to the function name during autocompletion. . .  Since essentially the parent:: is ignored, shouldn't this syntax be considered invalid??
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 11:01:29 2024 UTC