[PHP-BUG] Bug #52245 [NEW]: Private member of parent class accessible from child class.
From: Operating system: Windows 7 x64 PHP version: 5.3.2 Package: *General Issues Bug Type: Bug Bug description:Private member of parent class accessible from child class. Description: my_private_member; } } class Son extends Father { private $my_private_member = 'Son private member'; } //After init Son object, it has both private members, we can see it if we var_dump($son_instance); $son_instance = new Son; //Following manual php.net the output "Son private member" is expected here, but the result is "Father private member" $son_instance->show_private_member(); ?> Test script: --- my_private_member; } } class Son extends Father { private $my_private_member = 'Son private member'; } //After init Son object, it has both private members, we can see it if we var_dump($son_instance); $son_instance = new Son; //Following manual php.net the output "Son private member" is expected here, but the result is "Father private member" $son_instance->show_private_member(); ?> Expected result: Expected "Son private member". -- Edit bug report at http://bugs.php.net/bug.php?id=52245&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52245&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52245&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52245&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52245&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52245&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52245&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52245&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52245&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52245&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52245&r=support Expected behavior: http://bugs.php.net/fix.php?id=52245&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52245&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52245&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52245&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52245&r=php4 Daylight Savings:http://bugs.php.net/fix.php?id=52245&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52245&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52245&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52245&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52245&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52245&r=mysqlcfg
Bug #52245 [Opn]: Private member of parent class accessible from child class.
Edit report at http://bugs.php.net/bug.php?id=52245&edit=1 ID: 52245 User updated by: phpamid at gmail dot com Reported by: phpamid at gmail dot com Summary: Private member of parent class accessible from child class. Status: Open Type: Bug Package: *General Issues Operating System: Windows 7 x64 PHP Version: 5.3.2 New Comment: . class Son extends Father{private $x = 'SON'; // try to decomment this: //public function a(){echo $this->x;} } . I know if I override method a() in the child - everything will be ok, but it's not necessary to override method a(), because method a() is inherited form father class and it's public. p.s. if it's a bug, then it's php behavior. Previous Comments: [2010-07-04 13:50:26] giorgio dot liscio at email dot it i think that is a bug but i'm not sure if is a php behavior x;} } class Son extends Father{private $x = 'SON'; // try to decomment this: //public function a(){echo $this->x;} } $son_instance = new Son; $son_instance->a(); ?> -------------------- [2010-07-04 13:22:18] phpamid at gmail dot com Description: my_private_member; } } class Son extends Father { private $my_private_member = 'Son private member'; } //After init Son object, it has both private members, we can see it if we var_dump($son_instance); $son_instance = new Son; //Following manual php.net the output "Son private member" is expected here, but the result is "Father private member" $son_instance->show_private_member(); ?> Test script: --- my_private_member; } } class Son extends Father { private $my_private_member = 'Son private member'; } //After init Son object, it has both private members, we can see it if we var_dump($son_instance); $son_instance = new Son; //Following manual php.net the output "Son private member" is expected here, but the result is "Father private member" $son_instance->show_private_member(); ?> Expected result: Expected "Son private member". -- Edit this bug report at http://bugs.php.net/bug.php?id=52245&edit=1
Bug #52245 [Opn]: Private member of parent class accessible from child class.
Edit report at http://bugs.php.net/bug.php?id=52245&edit=1 ID: 52245 User updated by: phpamid at gmail dot com Reported by: phpamid at gmail dot com Summary: Private member of parent class accessible from child class. Status: Open Type: Bug Package: *General Issues Operating System: Windows 7 x64 PHP Version: 5.3.2 New Comment: as for your code: class A { private $a = "a"; } class B extends A { private $a = "b"; // is this an error? } i think every class has own private member, so there is no error. Ok, I got you. I hope that this issue will be clarified. Thank you for discussion. Previous Comments: [2010-07-04 14:32:12] giorgio dot liscio at email dot it in fact if you use protected instead of private it works as expected but the "private" issue should be clarified, i think * i'm sorry for the second post [2010-07-04 14:26:04] giorgio dot liscio at email dot it sure i know i don't need to override the method with the same one in the new class to fix this problem in the parent class the field is private... so theoretically i can not access the member in the derived class class A { private $a = "a"; } class B extends A { private $a = "b"; // is this an error? } it probably is, and maybe php should throw an error -------------------- [2010-07-04 14:00:51] phpamid at gmail dot com . class Son extends Father{private $x = 'SON'; // try to decomment this: //public function a(){echo $this->x;} } . I know if I override method a() in the child - everything will be ok, but it's not necessary to override method a(), because method a() is inherited form father class and it's public. p.s. if it's a bug, then it's php behavior. [2010-07-04 13:50:26] giorgio dot liscio at email dot it i think that is a bug but i'm not sure if is a php behavior x;} } class Son extends Father{private $x = 'SON'; // try to decomment this: //public function a(){echo $this->x;} } $son_instance = new Son; $son_instance->a(); ?> [2010-07-04 13:22:18] phpamid at gmail dot com Description: my_private_member; } } class Son extends Father { private $my_private_member = 'Son private member'; } //After init Son object, it has both private members, we can see it if we var_dump($son_instance); $son_instance = new Son; //Following manual php.net the output "Son private member" is expected here, but the result is "Father private member" $son_instance->show_private_member(); ?> Test script: --- my_private_member; } } class Son extends Father { private $my_private_member = 'Son private member'; } //After init Son object, it has both private members, we can see it if we var_dump($son_instance); $son_instance = new Son; //Following manual php.net the output "Son private member" is expected here, but the result is "Father private member" $son_instance->show_private_member(); ?> Expected result: Expected "Son private member". -- Edit this bug report at http://bugs.php.net/bug.php?id=52245&edit=1
Bug #52245 [Bgs]: Private member of parent class accessible from child class.
Edit report at http://bugs.php.net/bug.php?id=52245&edit=1 ID: 52245 User updated by: phpamid at gmail dot com Reported by: phpamid at gmail dot com Summary: Private member of parent class accessible from child class. Status: Bogus Type: Bug Package: *General Issues Operating System: Windows 7 x64 PHP Version: 5.3.2 New Comment: 1) Answer for your question "Are you looking for protected elements?" is "Bug #52245 Private member of parent class accessible from child class." 2) Why you say that show_private_member() belongs to Parent class, if it is inherited by its Child? In addition, I redefined the private member in Child class - then, according to the paradigm of OOP polimoryizm, the method should return a value of Child private member, otherwise all you have said is contrary to OOP, in particular, to polymorphism. Previous Comments: [2010-07-08 13:00:41] johan...@php.net You are calling show_private_member(). That method belongs to Father and therefore has access to Father's private elements. The method has no access to other class's private elements. Are you looking for protected elements? -------- [2010-07-04 15:11:05] phpamid at gmail dot com as for your code: class A { private $a = "a"; } class B extends A { private $a = "b"; // is this an error? } i think every class has own private member, so there is no error. Ok, I got you. I hope that this issue will be clarified. Thank you for discussion. [2010-07-04 14:32:12] giorgio dot liscio at email dot it in fact if you use protected instead of private it works as expected but the "private" issue should be clarified, i think * i'm sorry for the second post [2010-07-04 14:26:04] giorgio dot liscio at email dot it sure i know i don't need to override the method with the same one in the new class to fix this problem in the parent class the field is private... so theoretically i can not access the member in the derived class class A { private $a = "a"; } class B extends A { private $a = "b"; // is this an error? } it probably is, and maybe php should throw an error -------------------- [2010-07-04 14:00:51] phpamid at gmail dot com . class Son extends Father{private $x = 'SON'; // try to decomment this: //public function a(){echo $this->x;} } . I know if I override method a() in the child - everything will be ok, but it's not necessary to override method a(), because method a() is inherited form father class and it's public. p.s. if it's a bug, then it's php behavior. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/bug.php?id=52245 -- Edit this bug report at http://bugs.php.net/bug.php?id=52245&edit=1
Bug #52245 [Bgs->Opn]: Private member of parent class accessible from child class.
Edit report at http://bugs.php.net/bug.php?id=52245&edit=1 ID: 52245 User updated by:phpamid at gmail dot com Reported by:phpamid at gmail dot com Summary:Private member of parent class accessible from child class. -Status: Bogus +Status: Open Type: Bug Package:*General Issues Operating System: Windows 7 x64 PHP Version:5.3.2 Block user comment: N New Comment: Could you please answer to my questions? Previous Comments: [2010-07-14 09:25:32] phpamid at gmail dot com 1) Answer for your question "Are you looking for protected elements?" is "Bug #52245 Private member of parent class accessible from child class." 2) Why you say that show_private_member() belongs to Parent class, if it is inherited by its Child? In addition, I redefined the private member in Child class - then, according to the paradigm of OOP polimoryizm, the method should return a value of Child private member, otherwise all you have said is contrary to OOP, in particular, to polymorphism. [2010-07-08 13:00:41] johan...@php.net You are calling show_private_member(). That method belongs to Father and therefore has access to Father's private elements. The method has no access to other class's private elements. Are you looking for protected elements? -------- [2010-07-04 15:11:05] phpamid at gmail dot com as for your code: class A { private $a = "a"; } class B extends A { private $a = "b"; // is this an error? } i think every class has own private member, so there is no error. Ok, I got you. I hope that this issue will be clarified. Thank you for discussion. [2010-07-04 14:32:12] giorgio dot liscio at email dot it in fact if you use protected instead of private it works as expected but the "private" issue should be clarified, i think * i'm sorry for the second post [2010-07-04 14:26:04] giorgio dot liscio at email dot it sure i know i don't need to override the method with the same one in the new class to fix this problem in the parent class the field is private... so theoretically i can not access the member in the derived class class A { private $a = "a"; } class B extends A { private $a = "b"; // is this an error? } it probably is, and maybe php should throw an error The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/bug.php?id=52245 -- Edit this bug report at http://bugs.php.net/bug.php?id=52245&edit=1