protect方法
<?php
class Car {
private $speed = 0;
public function getSpeed() {
return $this->speed;
}
protected function speedUp() {
$this->speed += 10;
}
//增加start方法,使他能够调用受保护的方法speedUp实现加速10
public function start(){
$this->speedUp();
}
}
$car = new Car();
$car->start();
echo $car->getSpeed();
这里的speedUp不是已经定义为protected了吗?怎么还能在外部调用echo $car->getSpeed();