public means global and can be accessed by subclasses inside and outside the class;
$this->funcOne();
}
function func(){
echo $this->age.'
'.$this->name.'
'.$this-> sex.'
';
}
>name.'
'.$this->sex.'
';
} 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 means protected and can only be accessed in this class or subclass or parent class; Magic methods related to encapsulation:
__set(): It is a method that is automatically called when directly setting the property value of a private member
__get(): It is a method that is automatically called when it is directly getting the value of a private member property
__isset(); is a method that is automatically called when isset directly to check whether the private attributes in the object exist
__unset(); is a method that is automatically called when directly unset deletes the private attributes in the object
http://www.bkjia.com/PHPjc/327164.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/327164.html
TechArticle
public means global and can be accessed by both internal and external subclasses of the class; copy the code as follows: ?php class Test{ public $name='Janking', $sex='male', $age=23; function __construct(){ echo...