Re: Spec for scope resolution when overriding private methods
| From: | Stanislav Malyshev | Date: | Mon, 17 Aug 2015 00:39:07 +0000 |
| Subject: | Re: Spec for scope resolution when overriding private methods | ||
| References: | 1 | Groups: | php.standards |
| Request: | Send a blank email to standards-+get-845@lists.php.net to get a copy of this message | ||
Hi!
> I've been looking for an official answer for this behavior:
>
> http://stackoverflow.com/questions/3756609/strange-behavior-when-overriding-private-methods
In 14-classes, we read:
The members of a class each have a default or explicitly declared
visibility, which determines what source code can access them. A member
with private visibility may be accessed only from within its own class.
A member with protected visibility may be accessed only from within its
own class and from classes above and below it in the inheritance chain.
Access to a member with public visibility is unrestricted.
And:
Visibility of the overridden member can not be made more restrictive,
only more permissive (from private to protected to public).
When a private member is overridden, the methods of the defining class
still have access to the original private member, however non-static
public and protected members are shared across the inheritance chain.
From this, it follows that:
1. You can not override public with private
2. Private always belongs to its class
3. Public/protected are shared
--
Stas Malyshev
smalyshev@gmail.com