<?php
class Company{
public $name;//公共的;
protected $position;//受保护的,可以再子类调用
private $salary;//私有的,只能在类内调用;
public function __construct($name,$position,$salary)
{
$this->name=$name;
$this->position=$position;
$this->salary=$salary;
}
public function GetPosition(){
return $this->position;
}
public function GetSalary(){
$res = $this->salary;
if ($this->name == '杨俊杰') {
echo '这个人太厉害了,你这个渣渣不配查看他的工资';
}else{
return $res;
}
}
}
<?php
spl_autoload_register(function($className){
require __DIR__.'\public\\'.$className.'.php';
});
$Company = new Company('杨俊杰','总经理',50000);
// echo '我是受保护的属性值----》'.$Company->GetPosition();//调用受保护的属性
// echo $Company->GetSalary();调用私有的属性
?>