ID:               37320
 Updated by:       [EMAIL PROTECTED]
 Reported By:      php at dayclan dot org
-Status:           Open
+Status:           Assigned
 Bug Type:         Class/Object related
 Operating System: Windows Server 2003
 PHP Version:      5.1.4
 Assigned To:      helly


Previous Comments:
------------------------------------------------------------------------

[2006-05-05 03:59:10] php at dayclan dot org

Description:
------------
If a parent and child class both define the same member variable, and
if the visibility of the member variable in the parent is "private",
all references in the parent class will access that private variable. 
If the parent variable is protected or public, though, all references
in the parent class will access the child's variable.

The reason I suspect this is a bug and not designed behavior is because
the same is not true for member functions.  If a parent class has a
private member function and the child class defines the same member
function with protected visibility, all references to the function in
the parent class will go to the child class.

It's also annoying if you're using a child class to override a subset
of the functionality in a parent class. 

Reproduce code:
---------------
class Class1
{   
   private $var1 = 'Class1 var1';
   protected $var2 = 'Class1 var2';
   
   public function printOut() {
      echo $this->var1 . "\n";
      echo $this->var2 . "\n";
      echo $this->func1();
   }

   private function func1() {
      echo 'Class1 func1';
   }
}

class Class2 extends Class1
{
   protected $var1 = 'Class2 var1';
   protected $var2 = 'Class2 var2';

   protected function func1() {
      echo 'Class2 func1';
   }
}

$class2 = new Class2();
$class2->printOut();

Expected result:
----------------
Class2 var1
Class2 var2
Class2 func1

Actual result:
--------------
Class1 var1
Class2 var2
Class2 func1


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=37320&edit=1

Reply via email to