php.net |  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
Votes:2
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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: agigames at agigames dot com
New email:
PHP Version: OS:

 

 [2004-03-02 23:23 UTC] agigames at agigames dot com
Description:
------------
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".

Patches

Pull Requests

History

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

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

$obj2 = new childclass;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC