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>";
}
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>";
}
有些东西封装起来就能成为一个整体这个意思我自学没多长时间,我知道只要把private改成public就对了,但以后再遇到这种情况该怎么办呢?哪种是对啊?