|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16847 initialization function in extended class resets parent class variables
Submitted: 2002-04-26 06:54 UTC Modified: 2002-04-26 07:43 UTC
From: alexg at syspro dot co dot za Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.1.2 OS: linux 2.4.0
Private report: No CVE-ID: None
 [2002-04-26 06:54 UTC] alexg at syspro dot co dot za
When including an initialization function within both A and B classes, creating an instance of he extending B class resets the variable
value created by initialization function withing the A class

class A {
	var $var_a;
	function A() {
		$this->var_a = "a";

class B extends A {
	var $var_b;
	function B() {
		$this->var_b = "b";

$test = new B;
echo $test->var_a; //no output unless I comment out function B() in class B
echo $test->var_b;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-26 07:43 UTC]
You have to call the parents constructor explicitely. That's by design.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Nov 29 21:03:58 2022 UTC