Re: [STANDARDS] Spec for scope resolution when overriding private methods
[email protected] (Stanislav Malyshev)
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
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 [email protected]