php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
28 - 14 = ?
Subscribe to this entry?

 
 [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;

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-26 07:43 UTC] mfischer@php.net
You have to call the parents constructor explicitely. That's by design.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC