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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: alexg at syspro dot co dot za
New email:
PHP Version: OS:

 

 [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: Wed Apr 24 01:01:31 2024 UTC