<?php
header('Content-type:text/html;charset=utf-8');
class Staff
{
private $name ;
// public $age ;
//public $salary;
就是这里 不可以把age 和salary改成无形的
公共函数 __construct($name,$age,$salary)
{
$this->name = $name;
$this->age = $age;
$this->salary =$salary;
}
public function __get($name)
{
return $this->name;
}
公共函数 __set($name,$value)
{
if($name === 'age')
{
return false;
}
$this- >name=$value;
}
}
$obj=new Staff('22',24,500);
//echo $ obj->名称;
echo $obj->age;
echo '
echo $obj- >姓名;
echo '
echo $obj->salary;
类里面的私有成员没有数量限制