Warning: The magic method __get() must have public visibility and cannot be static in D:\wamp\www\1\Person.class.php on line 44Warning: The magic method __set() must have public visibility and cannot be static in D:\wamp\www\1\Person.class.php on line 53Warning: The magic method __isset() must have public visibility and cannot be static in D:\wamp\www\1\Person.class.php on line 88Warning: The magic method __unset() must have public visibility and cannot be static in D:\wamp\www\1\Person.class.php on line 94我看lamp教程上面没报警告,我这个怎么报警告了还有这么用到底对不对?源码:
class Person {
private $name;
private $age;
private $sex;

function __construct($name="", $age=0, $sex="男"){
$this->name=$name;
$this->age=$age;
$this->sex=$sex;
} private function __get($proName){
if($proName=="age"){
if($this->age>40)
return $this->age-10;
} return $this->$proName;
} private function __set($proName, $proValue){
if($proName=="age"){
if($proValue > 100 || $proValue < 0)
return;
} $this->$proName=$proValue;
}
function say(){
echo "我的名子:{$this->name},我的年龄:{$this->age},我的性别:{$this->sex}。<br>";
} function run(){
$this->left();
$this->left();
$this->right();
$this->right();
$this->gogo();
$this->gogo();
$this->gogo();
} private function left(){
echo "LLLLLLLLLLLLL<br>";
}
private function right(){
echo "RRRRRRRRRRRRRR<br>";
} private function gogo(){
echo "GGGGGGGGGGGGGGGGG<br>";
} private function __isset($proName){
if($proName=="age")
return false;
return isset($this->$proName);
} private function __unset($proName){
unset($this->$proName);
} function eat(){

} function __destruct(){
echo $this->name."再见!<br>";
}
}$p1=new Person("zhangsan", 80, "女");
$p2=new Person("lisi", 25);
$p3=new Person("wangwu");unset($p1->name);
if(isset($p1->name)){
echo "存在<br>";
}else{
echo "没有这个成员 <br>";
}

解决方案 »

  1.   

    魔术方法__get() 必须声明为public 并且不能是静态的
      

  2.   

    绝对没看错,lamp兄弟连的教程
      

  3.   

    正常啊, 只是个warning,他们把错误提示关了....给个链接, 让我们去嘲笑嘲笑.... :)
      

  4.   

    这节讲的是面向对象封装,说的是
    有些东西封装起来就能成为一个整体这个意思我自学没多长时间,我知道只要把private改成public就对了,但以后再遇到这种情况该怎么办呢?哪种是对啊?
      

  5.   

    手册上面写的很清楚,魔术方法都要public楼上没报错估计是ini里面把错误报告的选项关闭了
      

  6.   

    哄哄,楼主这个例子俺看过,那本叫《细说php》来着,果然误人子弟的例子。
      

  7.   

    也不要那样说。一本书有一点bug也没有什么。总得来说还是可以的。我的了多部php的书。也没有那本比它好很多。