php超简单问题__set和__get的问题 本帖最后由 steavenhe 于 2010-06-26 11:31:03 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 class classModel{ var $attribute; function __get($name) {echo"获取私有属性值调用__get()方法<br>"; if(isset($this->$Deliver_name)) { return ($this -> $name); } else { return(NULL); } } function __set($name,$value) { echo"设置私有属性值调用__set()方法<br>"; $this -> $name = $value; }}$a = new classModel();$a -> attribute = 5;//__set()设置属性值$a -> attribute; //__get()检查属性值 试了一下楼主给出的代码,看上去很正常啊,跟楼主描述的不太一样。(难道是 PHP 版本问题?)我想楼主对于 __get() 和 __set() 的理解应该是正确的。我把楼主的代码稍微改了一下,供参考:class Test{ private $name = ''; private $pwd = ''; function __construct() { echo "hello"."<br />"; } function __set($property,$value) { if ( $property == 'name' ) $this->name = $value; else if ( $property == 'pwd' ) $this->pwd = $value; } function __get($property) { if ( $property == 'name' ) return $this->name; else if ( $property == 'pwd' ) return $this->pwd; }} //__get()方法用来获取私有属性private function__get($property_name){if(isset($this->$property_name)){return($this->$property_name);}else{return(NULL);}}//__set()方法用来设置私有属性private function__set($property_name,$value){$this->$property_name=$value;} class classModel{ var $attribute; function __get($name) {echo"获取私有属性值调用__get()方法<br>"; if(isset($this->$name)) {return ($this -> $name); } else { return(NULL); } } function __set($name,$value) { echo"设置私有属性值调用__set()方法<br>"; $this -> $name = $value; }}$a = new classModel();$a -> attribute = 5;//__set()设置属性值$a -> attribute; //__get()检查属性值 基于window下的wamp2.2+eclipse3.7的配置 php数组整合问题 验证码问题 50分请高手看一下为什么会这样,对方到底用了什么技术? 框架开发与搜索引擎 php,怎么样取得js内的返回变量呀? php连mysql的菜鸟问题 怎么合并数组? 请帮忙 从网上得一个登陆程序,我想把它作来,可没成功,并引出了一些疑问(用号标出)请给解释以下 如何从数据库中读出来数据? 有个正则不会,帮忙写下?
{
var $attribute;
function __get($name)
{
echo"获取私有属性值调用__get()方法<br>";
if(isset($this->$Deliver_name))
{
return ($this -> $name);
}
else
{
return(NULL);
}
}
function __set($name,$value)
{
echo"设置私有属性值调用__set()方法<br>";
$this -> $name = $value;
}}
$a = new classModel();
$a -> attribute = 5;//__set()设置属性值
$a -> attribute; //__get()检查属性值
class Test{
private $name = '';
private $pwd = ''; function __construct() {
echo "hello"."<br />";
} function __set($property,$value) {
if ( $property == 'name' )
$this->name = $value;
else if ( $property == 'pwd' )
$this->pwd = $value;
} function __get($property) {
if ( $property == 'name' )
return $this->name;
else if ( $property == 'pwd' )
return $this->pwd;
}
}
private function__get($property_name)
{
if(isset($this->$property_name))
{
return($this->$property_name);
}else{
return(NULL);
}
}
//__set()方法用来设置私有属性
private function__set($property_name,$value)
{
$this->$property_name=$value;
}
class classModel
{
var $attribute;
function __get($name)
{
echo"获取私有属性值调用__get()方法<br>";
if(isset($this->$name))
{
return ($this -> $name);
}
else
{
return(NULL);
}
}
function __set($name,$value)
{
echo"设置私有属性值调用__set()方法<br>";
$this -> $name = $value;
}}
$a = new classModel();
$a -> attribute = 5;//__set()设置属性值
$a -> attribute; //__get()检查属性值