私有字段private也可以外部访问

<?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



?>
原文地址:https://www.cnblogs.com/cp168168/p/7244075.html