为什么__set()和__get()私有了,还是可以执行?
来源:互联网 发布:淘宝直通车的使用规则 编辑:程序博客网 时间:2024/05/01 23:21
//__set()和__get()方法私有了,还是可以执行,
//是因为目前程序的指针已经在类内了。而类内可以执行封装的方法
//类内执行私有方法,不会出现任何错误。
//__set()和__get()其实就是php内置的方法
class Computer {
private $_name;
private $_model;
private $_cpu;
//用private私有__set()和__get()方法,防止外部直接访问
$this->$_key = $_value;
}
private function __get($_key) {
return $this->$_key;
}
}
$computer = new Computer();
$computer->_name = '联想';
$computer->_cpu = '四核';
$computer->_model = 'i7';
echo $computer->_name;
echo $computer->_cpu;
echo $computer->_model;
0 0
- 为什么__set()和__get()私有了,还是可以执行?
- PHP中的__get()和__set()方法获取设置私有属性
- __set和__get方法
- 魔术方法__set()和__get()
- php __set()和__get()函数
- __get和__set的用法
- php5类中的__get()和__set()方法用于private私有属性
- __get(),__set()
- PHP5 之 __set()和__get() 函数
- __call、__set 和 __get的用法
- OOP中__set()和__get()方法
- PHP中__get()和__set的用法
- php __set和__get的用法
- PHP魔术方法之__set()和__get()
- php __set 和 __get方法使用介绍
- PHP 魔术方法之"__set()"和"__get"
- php魔术方法__get和__set详解
- php中__get()和__set的用法
- android开发时的参考
- N-Queens II
- No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
- UIAlertView 警告框
- 学习之路
- 为什么__set()和__get()私有了,还是可以执行?
- [191]Number of 1 Bits
- 给字符数组赋值的方法
- leetCode 98:Validate Binary Search Tree
- 初识Android Studio,遇到了太多太多问题
- 蟠桃记
- LeetCode 21_Merge Two Sorted Lists
- 系统测试
- 《软工视频之微观了解一》