Bug #52245 [Opn->Bgs]: Private member of parent class accessible from child class.
| From: | johannes@php.net | Date: | Thu, 08 Jul 2010 11:00:41 +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-152218@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
New Comment:
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?
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[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
<?php
class Father{private $x = 'FATHER';
public function a(){echo $this->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();
?>
------------------------------------------------------------------------
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