面向对象的封装性:
1,就是把对象的成员(属性,方法)结合成一个独立的相同单位,并尽可能隐藏对象的内部细节
public protected
private 私有的,用这个关键字修饰的成员,只能在对象内部访问(只有用$this访问),不能在对象外部使用
示例:
JTBC CMS(5.0) 是一款基于PHP和MySQL的内容管理系统原生全栈开发框架,开源协议为AGPLv3,没有任何附加条款。系统可以通过命令行一键安装,源码方面不基于任何第三方框架,不使用任何脚手架,仅依赖一些常见的第三方类库如图表组件等,您只需要了解最基本的前端知识就能很敏捷的进行二次开发,同时我们对于常见的前端功能做了Web Component方式的封装,即便是您仅了解HTML/CSS也
立即学习“PHP免费学习笔记(深入)”;
class Person{
private $name;
private $age;
private $sex;
function __construct($name="",$age=20,$sex="male"){
$this->name=$name;
$this->age=$age;
$this->sex=$sex;
}
function getPro($name){
return $this->$name;
}
function setAge($age){
if($age>100$age<0){
return;
}
$this->age=$age;
}
function getAge(){
if($this->age<30){
return $this->age;
}elseif($this->age<40){
return $this->age-5;
}elseif($this->age<50){
return $this->age-10;
}else{
return $this->age-15;
}
}
function say(){
echo "我的名字是:".$this->name.",年龄是:".$this->age.",性别是:".$this->sex.'
';
}
function __destruct(){
echo $this->name.",再见"."
";
}
}
$p1=new Person("rayhooo",26,"male");
$p1->say();
echo $p1->getPro("name").'
';
$p1->setAge(45);
echo $p1->getAge().'
';










