Home > Backend Development > PHP Tutorial > 小弟我什么小弟我这里返回不了姓名和年龄

小弟我什么小弟我这里返回不了姓名和年龄

WBOY
Release: 2016-06-13 13:34:17
Original
827 people have browsed it

我什么我这里返回不了姓名和年龄

class Person{
? private $name;
? private $sex;
? private $age;
? ?
? //构造方法
? function __construct($name="",$sex="男",$age=1){
? $this ->name=$name;
? $this ->sex=$sex;
? $this->age=$age;
? }
? ?
? //添加__get()方法
? public function __get($propertName){
? if($propertName=="sex"){
? return "保密";
? }
? else if($propertyName=="age")
? {
? if($this->age>30)
? return $this->age-10;
? ?
? else
? return $this->$propertyName;
? ?
? }
? else
? {
? return $this->$propertyName;
? }
? ?
? }
}

$person1=new Person("张三","男",20);

echo "姓名:".$person1->name."
";
echo "性别:".$person1->sex."
";
echo "年龄:".$person1->age."
";


?>

我什么我这里返回不了姓名和年龄?
返回的是下面:

姓名:
性别:保密
年龄:
?请高手解答下 谢谢!

------解决方案--------------------
propertyName !== propertName

仔细看
------解决方案--------------------
propertyName !== propertName

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template