ID: 37320 Updated by: [EMAIL PROTECTED] Reported By: php at dayclan dot org -Status: Assigned +Status: Bogus Bug Type: Class/Object related Operating System: * -PHP Version: 5.1.4 +PHP Version: 5.* Assigned To: helly New Comment:
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 your printout function is defined in Class1 thuse the printout is done with Class1 context in which Class1::var1 is valid and Class2::var1 cannot be seen. Hint use var_dump() instead of your printout function: [EMAIL PROTECTED] /usr/src/php-cvs $ php ~/tmp/bug37320.php make: `sapi/cli/php' is up to date. object(Class2)#1 (3) { ["var1":protected]=> string(11) "Class2 var1" ["var2":protected]=> string(11) "Class2 var2" ["var1":"Class1":private]=> string(11) "Class1 var1" } [EMAIL PROTECTED] /usr/src/php-cvs $ ../PHP_5_2/sapi/cli/php ~/tmp/bug37320.php object(Class2)#1 (3) { ["var1:protected"]=> string(11) "Class2 var1" ["var2:protected"]=> string(11) "Class2 var2" ["var1:private"]=> string(11) "Class1 var1" } [EMAIL PROTECTED] /usr/src/php-cvs $ ../PHP_5_1/sapi/cli/php ~/tmp/bug37320.php object(Class2)#1 (3) { ["var1:protected"]=> string(11) "Class2 var1" ["var2:protected"]=> string(11) "Class2 var2" ["var1:private"]=> string(11) "Class1 var1" } 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