An interpreter (or a compiler in another OOP language) checks access one step at a time.
When you call $d->GetPrivate(); The context check interpreter in this is the main one (public context, since I assume that you are not associated with the Drerived or Base class) and GetPrivate() is a public method, Thus, $d->GetPrivate(); allowed in this context, so no errors.
In GetPrivate() context is a $d object like Base , and access to z is a private element of the current object ( $d ). Therefore, access is valid.
The concept that plays here is Data Hiding (access control) and Encapsulation (a combination of data and functions).
Inheritance for playback is only to use GetPrivate() of Base , since it belongs to the Derived object.
It is true that there is still a link to personal data, but this link is not direct. The importance is that access occurs as a Base valid class .
So, to answer your question:
YES! The interpreter continues to monitor which inherited functions from the base class and the possible references they contain for private members that are available only for this base class.
Hope this helps.
Nawaman
source share