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] [email protected]
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