#43083 [Opn->Bgs]: Protected method access from outside class.
| From: | helly@php.net | Date: | Tue, 23 Oct 2007 16:09:40 +0000 |
| Subject: | #43083 [Opn->Bgs]: Protected method access from outside class. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-118879@lists.php.net to get a copy of this message | ||
ID: 43083
Updated by: helly@php.net
Reported By: purpurby at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: RedHat
PHP Version: 5.2.4
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
First part is perfectly right. As binding happens at compile time only
relevant part is that C is-a A, hence inside C calls to A's protected
members are fine. The other thing is a bit odd since technically C and B
are different things. However what you call is inside A and both have A
as a common root, hence that is fine as well.
Previous Comments:
------------------------------------------------------------------------
[2007-10-23 14:22:52] purpurby at gmail dot com
Description:
------------
Availability to call protected method from outside class or its
descendants.
Reproduce code:
---------------
<?php
class a
{
protected function aa()
{
echo "a-aa\n";
}
}
class b extends a
{
protected function aa()
{
echo "b-aa\n";
}
}
// Extends is affects on the behaviour:
// - When "c" extends the "a" - not correct behaviour: working as in
"Actual result"
// - When "c" NOT extends the "a" - correct behaviour: working as in
"Expected result"
class c extends a
{
public function cc()
{
$obj = new a();
$obj->aa();
$obj2 = new b();
$obj2->aa();
}
}
$c = new c();
$c->cc();
?>
Expected result:
----------------
Fatal error: Call to protected method a::aa() from context 'c'
Actual result:
--------------
a-aa
b-aa
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43083&edit=1