首页上一页 1 下一页尾页 1 条记录 1/1页
什么是 PHP的序列化对象? 谢谢老师
发表在PHP图书答疑
2014-12-09
是否精华
是
否
版块置顶:
是
否
还有着个编程代码, type 的值如何输出来的 变量name被初始化为:0; 为什么输出的事0 不是$value 请老师解惑!
<?php
class SportObject
{
private $type = ' ';
public function getType(){
return $this -> type;
}
private function __get($name){
if(isset($this ->$name)){
echo '变量'.$name.'的值为:'.$this -> $name.'<br>';
}
else{
echo '变量'.$name.'未定义,初始化为0<br>';
$this -> $name = 0;
}
}
private function __set($name, $value){
if(isset($this -> $name)){
$this -> $name = $value;
echo '变量'.$name.'赋值为:'.$value.'<br>';
}else{
$this -> $name = $value;
echo '变量'.$name.'被初始化为:'.$value.'<br>';
}
}
}
$MyComputer = new SportObject();
$MyComputer -> type = 'DIY';
$MyComputer -> type;
$MyComputer -> name;
?>
<?php
class SportObject
{
private $type = ' ';
public function getType(){
return $this -> type;
}
private function __get($name){
if(isset($this ->$name)){
echo '变量'.$name.'的值为:'.$this -> $name.'<br>';
}
else{
echo '变量'.$name.'未定义,初始化为0<br>';
$this -> $name = 0;
}
}
private function __set($name, $value){
if(isset($this -> $name)){
$this -> $name = $value;
echo '变量'.$name.'赋值为:'.$value.'<br>';
}else{
$this -> $name = $value;
echo '变量'.$name.'被初始化为:'.$value.'<br>';
}
}
}
$MyComputer = new SportObject();
$MyComputer -> type = 'DIY';
$MyComputer -> type;
$MyComputer -> name;
?>