Public represents the global, and the inner and outer subclasses of the class can be accessed;
Copy CodeThe code is as follows:
Class test{
Public $name = ' janking ',
$sex = ' Male ',
$age = 23;
function __construct () {
echo $this->age. '
'. $this->name. '
'. $this->sex. '
';
}
function func () {
echo $this->age. '
'. $this->name. '
'. $this->sex. '
';
}
}
$P =new Test ();
Echo '
';
$P->age=100;
$P->name= "Rainy";
$P->sex= "female";
$P->func ();
?>
Public
Private means that only this class can be used internally;
Copy CodeThe code is as follows:
Class test{
Private $name = ' janking ',
$sex = ' Male ',
$age = 23;
function __construct () {
$this->funcone ();
}
function func () {
echo $this->age. '
'. $this->name. '
'. $this->sex. '
';
}
Private Function Funcone () {
echo $this->age. '
'. $this->name. '
'. $this->sex. '
';
}
}
$P =new Test ();
Echo '
';
$P->func ();
$P->age=100; Cannot access private property Test:: $age
$P->name= "Rainy"; Cannot access private property Test:: $name
$P->sex= "female"; Cannot access private property Test:: $female
$P->funcone (); Call to Private Method Test::funcone () from context '
?>
Private
Protected represents a protected, only accessible in this class or subclass or parent class, and encapsulation-related magic methods:
__set (): A method that is automatically called when a private member property value is set directly
__get (): method that is called automatically when a private member property value is obtained directly
__isset (); This method is called automatically when the private property in the object is isset to see if it is stored.
__unset (); Is the method that is called automatically when you delete a private property in an object directly unset