We all know the ideas access modifier, public, protected, and private. Do we know that private attributes in inheritance can be inherited? Let me do a small experiment.
Class {
Private $ class_name = 'in a class ';
Public $ autthor;
Protected $ book;
Public Function Saya (){
Var_dump ($ this );
Echo $ this-> class_name;
}
}
Class B extends {
Private $ class_name = 'in B class ';
Public $ author;
Protected $ book;
Public Function Sayb (){
Var_dump ($ this );
Echo $ this-> class_name;
}
}
// Observe the output details. The private attribute stores two values, and the others only have one attribute value! Why are there two attributes of $ O object? The reason is described below.
$ O = new B;
$ O-> Sayb ();
Echo '<HR> ';
$ O-> Saya ();
/**
The reason is that PHP does not overwrite the object's private attributes when saving them. It also saves all the private attributes (even with the same name) and records the class to which this private property belongs!
Private attributes may appear. Different values of attributes with the same name may occur!
*/
Private in Object Oriented