本文整理汇总了PHP中Car::getSpeed方法的典型用法代码示例。如果您正苦于以下问题:PHP Car::getSpeed方法的具体用法?PHP Car::getSpeed怎么用?PHP Car::getSpeed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car::getSpeed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMaxSpeed
public function testMaxSpeed()
{
$car = new Car();
for ($i = 0; $i < 10; $i++) {
$car->accelerate();
}
$this->assertEquals(100, $car->getSpeed());
$car->accelerate();
$this->assertEquals(100, $car->getSpeed());
}
示例2: getSpeed
{
if ($this->_speed <= 0) {
return false;
}
$this->_speed -= 10;
return true;
}
public function getSpeed()
{
return $this->_speed;
}
}
$myCar = new Car();
$myCar->color = "red";
$myCar->manufacturer = "Volkswagen";
$myCar->model = "Beetle";
echo "<p>I'm driving a {$myCar->color} {$myCar->manufacturer} {$myCar->model}.</p>";
echo "<p>Stepping on the gas...<br />";
while ($myCar->accelerate()) {
echo "Current speed: " . $myCar->getSpeed() . " mph<br />";
}
echo "</p><p>Top speed! Slowing down...<br />";
while ($myCar->brake()) {
echo "Current speed: " . $myCar->getSpeed() . " mph<br />";
}
echo "</p><p>Stopped!</p>";
?>
</body>
</html>