Bug #52245 [Opn->Bgs]: Private member of parent class accessible from child class.
| From: | johannes@php.net | Date: | Wed, 28 Jul 2010 12:25:06 +0000 |
| Subject: | Bug #52245 [Opn->Bgs]: Private member of parent class accessible from child class. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-152881@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52245&edit=1
ID: 52245
Updated by: johannes@php.net
Reported by: phpamid at gmail dot com
Summary: Private member of parent class accessible from child
class.
-Status: Open
+Status: Bogus
Type: Bug
Package: *General Issues
Operating System: Windows 7 x64
PHP Version: 5.3.2
Block user comment: N
New Comment:
.
Previous Comments:
------------------------------------------------------------------------
[2010-07-28 14:23:11] johannes@php.net
Private enforces encapsulation, a key element of OOP. The current
behavior ensures you can extend the class without an effect on
show_private_member() and whatever happens in there. With your change
extending the class can hae an effect (by accident) on the method.
------------------------------------------------------------------------
[2010-07-27 09:43:48] phpamid at gmail dot com
Could you please answer to my questions?
------------------------------------------------------------------------
[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] johannes@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.
------------------------------------------------------------------------
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