Bug #62045 [Opn->Nab]: public access to a protectec method
| From: | cataphract@php.net | Date: | Wed, 16 May 2012 08:51:07 +0000 |
| Subject: | Bug #62045 [Opn->Nab]: public access to a protectec method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-170494@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62045&edit=1
ID: 62045
Updated by: cataphract@php.net
Reported by: gonzalo123 at gmail dot com
Summary: public access to a protectec method
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: 5.3.13
Block user comment: N
Private report: N
New Comment:
Access is granted on a class, not instance basis. This is by design.
Previous Comments:
------------------------------------------------------------------------
[2012-05-16 08:23:45] gonzalo123 at gmail dot com
Description:
------------
This code works, but it shouldn't, because AnotherClass::foo is protected.
It works only if "OneClass" extends "AnotherClass". If we dont't extends
"OneClass" with "AnotherClass" (in this example we don't need it) we will
see the
normal error:
Fatal error: Call to protected method AnotherClass::foo() from context 'OneClass'
Test script:
---------------
class AnotherClass {
protected function foo() {
return "bar";
}
}
class OneClass extends AnotherClass {
private $object;
public function __construct(AnotherClass $object) {
$this->object = $object;
}
public function myFunction() {
return $this->object->foo();
}
}
$obj = new OneClass(new AnotherClass());
echo $obj->myFunction();
Expected result:
----------------
Fatal error: Call to protected method AnotherClass::foo() from context 'OneClass'
Actual result:
--------------
"bar" (without Fatal error)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62045&edit=1