|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27476 Extends and parent vars
Submitted: 2004-03-02 23:23 UTC Modified: 2004-03-03 04:42 UTC
Avg. Score:3.5 ± 1.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: agigames at agigames dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.0b4 (beta4) OS: Windows XP
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.
Bug Type:
From: agigames at agigames dot com
New email:
PHP Version: OS:


 [2004-03-02 23:23 UTC] agigames at agigames dot com
This problem occurs in both PHP 4.3.5RC3 and in PHP 5.0.0b4. The constructor function of the child class does not have the proper var's set in it from the parent class.

Reproduce code:
class parentclass {
	public $var = 'test';

	function parentclass() {
		$this->var = 'test2';

class childclass extends parentclass {
	function childclass() {
		print $this->var;

$obj = new parentclass;
$obj2 = new childclass;

Expected result:
Well I expected it to print "test2".

Actual result:
But instead it prints the value that the public var was initialized as "test".


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-03 04:42 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is correct, PHP will not automatically call the parent constructor if you do:

$obj2 = new childclass;
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 23:03:35 2021 UTC