自动加载案例,访问

Original 2019-03-12 19:02:40 325
abstract:name=$name;


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;

}

}

}


spl_autoload_register(function($className){

require __DIR__.'\public\\'.$className.'.php';

});




$Company = new Company('杨俊杰','总经理',50000);


// echo '我是受保护的属性值----》'.$Company->GetPosition();//调用受保护的属性


// echo $Company->GetSalary();调用私有的属性







?>

YZ7ZDUJA6U]YVD@RX0$_%MB.png

Correcting teacher:韦小宝Correction time:2019-03-13 09:07:52
Teacher's summary:写的还是很不错的 自动加载在自己写案例的时候经常会使用到 这个要多去练习哦

Release Notes

Popular Entries