您的位置:首页 > 其它

私有字段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



?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: