<?php
header('Content-type:text/html;charset=utf-8');
class Staff
{
private $name ;
// public $age ;
//public $salary;
就是此里 不可以 把年齢 和給与 修正私有的
public function __construct($name,$age,$salary)
{
$this->name = $name;
$this->age = $age;
$this->salary =$salary;
}
public function __get($name)
{
return $this->name;
}
public function __set($name,$value)
{
if($name === 'age')
{
return false;
}
$this- >name=$value;
}
}
$obj=new Staff('22',24,500);
//echo $ obj->name;
echo $obj->age;
echo '
echo $obj- >名前;
echo '
echo $obj->salary;