|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-01-16 09:25 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 08:00:02 2025 UTC |
Description: ------------ I define variable A within parent class cFoo, and initialise it within the class Constructor. I redefine variable A within child class cBar, and initialise it within the class Constructor which then calls the parent class Constructor. The parent constructor modifies the child instance of property A rather than the parent instance. Reproduce code: --------------- <?php /* Inheritance test2. Inherited Vars */ class cFoo { var $A; function cFoo() /* constructor */ { $this->A = "cFoo_A"; } function Display() { print("Within cFoo::Display; property A = '$this->A'; should be 'cFoo_A'<br>\n"); } }; class cBar extends cFoo { var $A; // redefines A function cBar() /* constructor */ { $this->A = "cBar_A"; $this->cFoo(); /* parent constructor */ } function Display() { print("Within cBar::Display; property A = '$this->A'; should be 'cBar_A'<br>\n"); } }; $foo1 = new cFoo; $foo1->Display(); $bar1 = new cBar; $bar1->Display(); exit; ?> Expected result: ---------------- Within cFoo::Display; property A = 'cFoo_A'; should be 'cFoo_A' Within cBar::Display; property A = 'cBar_A'; should be 'cBar_A' Actual result: -------------- Within cFoo::Display; property A = 'cFoo_A'; should be 'cFoo_A' Within cBar::Display; property A = 'cFoo_A'; should be 'cBar_A'