|  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
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:
Solve the problem:
10 + 3 = ?
Subscribe to this entry?

 [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-2023 The PHP Group
All rights reserved.
Last updated: Wed Dec 06 05:01:28 2023 UTC