码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-07-27 12:48:20      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:php   字段   color   font   echo   val   .net   gic   cti   

<?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也可以外部访问

标签:php   字段   color   font   echo   val   .net   gic   cti   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!