私有字段private也可以外部访问
2017-07-27 11:48
204 查看
<?php
//私有字段private也可以外部访问
class nowamagic {
private $domain;
function __get($key){
return "使用get访问属性".$this->$key;
}
function __set($key,$value){
$this->$key = $value;
echo("使用set设置属性$key, 赋值为:<font color=red>$value</font>");
}
}
$ins = new nowamagic();
$ins->domain = "nowamagic.net";
echo '<br />';
echo $ins->domain;
//输出
//使用set设置属性domain, 赋值为:nowamagic.net
//使用get访问属性nowamagic.net
?>
相关文章推荐
- JavaSE8基础 内部类可以访问外部类的私有成员
- 外部类可以自由访问内部类的private方法
- 内部类之设计模式-内部类可以访问外部类的私有成员
- 内部类之设计模式-内部类可以访问外部类的私有成员
- 私有字段能不能从类的外部访问?
- [置顶] c++,vc6.0,中友元函数,无法访问私有字段(private)的问题(problem),cannot access private member declared in class 'Date'
- 外部类可以访问内部类的私有成员
- c++,vc6.0,中友元函数,无法访问私有字段(private)的问题(problem),cannot access private member declared in class 'Date'
- 没错!java中private字段也是可以访问D!
- Java的private和final字段竟然可以被外部类修改?
- 外部类是否可以访问内部类private元素
- private 私有的 外部不能访问的
- 通过外部指针可以访问类的私有成员
- 在内部类中可以访问其外部类的所有域,即使是私有域
- 震惊!外部类可以访问内部类private变量
- Android 中利用反射访问private修饰的字段和方法
- 深入理解Java中为什么内部类可以访问外部类的成员
- 测试在类的内部是否可以访问对象的私有成员
- C++对象中的私有成员变量也可以被访问
- 深入理解Java中为什么内部类可以访问外部类的成员