首页 > 其他 > 详细

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

时间:2017-07-27 12:20:24      阅读:206      评论:0      收藏:0      [点我收藏+]
<?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



?>

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

原文:http://www.cnblogs.com/cp168168/p/7244075.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!