From:             jamie at sailor dot org dot uk 
Operating system: Win2K
PHP version:      4.3.4
PHP Bug Type:     Class/Object related
Bug description:  Redefined property in child class modified out of context in parent 
class

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'


-- 
Edit bug report at http://bugs.php.net/?id=26921&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=26921&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=26921&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=26921&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=26921&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=26921&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=26921&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=26921&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=26921&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=26921&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=26921&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=26921&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=26921&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26921&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=26921&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=26921&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=26921&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26921&r=float

Reply via email to