public、private、protected的区别
2016-06-16 17:08
302 查看
public 公共的 谁都可以用,也可以修改 protected 受保护的 只有自己和后代可以使用和修改 private 私有的 只有自己可以使用和修改
eg:
class MyTest{ public $name; protected $sex; private $birth; public function __construct($name,$sex,$birth){ $this-> name = $name; $this-> sex = $sex; $this-> birth = $birth; } public function getBirth(){ return $this->birth; } public function setSex($sex){ if($sex==='男'||$sex==='女'){ $this->sex = $sex; }else{ return null; } } } $test = new MyTest('李四','男',time()); echo $test->name; echo $test->getBirth();
相关文章推荐
- ORA-19809: 超出了恢复文件数的限制解决
- 基于Eclipse Maven的Spring4/Spring-MVC/Hibernate4整合之三:hibernate4泛型dao的应用
- laragon环境更新安装新的php版本操作方法
- 顺序栈和链栈实现
- Linux ssh免密登录
- UVa 10970
- 分类算法 之 朴素贝叶斯--理论解读
- Linux下的常用性能查询命令top、vmstat、gprof、pidstat
- 接口自动化学习笔记
- BZOJ NOI十连测 第二测 T2
- mybatis代码生成器配置文件详解
- 迪米特法则(Law of Demeter)LoD
- 关于ExpandableListView展开滑动的问题
- 正则表达式基本语法
- iOS利用GCDAsyncSocket发送语音,以及语音wav转码amr
- iOS利用GCDAsyncSocket发送语音,以及语音wav转码amr
- 暴雪hash来作整数的hash
- [Learning OpenCV入门2]CMake生成源代码以及HighGUI部分内容
- Permutations II
- QGIS在windows下的编译