本文整理汇总了PHP中Car::startEngine方法的典型用法代码示例。如果您正苦于以下问题:PHP Car::startEngine方法的具体用法?PHP Car::startEngine怎么用?PHP Car::startEngine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car::startEngine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getStatus
class SUV extends Car
{
public $has4WD = false;
// child classes can override parent properties
public function getStatus()
{
// child classes can still access parent methods using parent::
return parent::getStatus();
}
}
$myCar = new Car('Mercedes', '760GL', 'black');
echo '<p>The color of my car is ' . $myCar->color . '.</p>';
$yourCar = new SUV('Hummer', 'H2', 'red');
echo '<p>The color of your car is ' . $yourCar->color . '.</p>';
echo '<p>My car status is ' . $myCar->getStatus() . '</p>';
$myCar->startEngine();
echo '<p>My car status is ' . $myCar->getStatus() . '</p>';
//$yourCar->startEngine();
echo '<p>Your car status is ' . $yourCar->getStatus() . '</p>';
echo '<p>Your car ' . (empty($yourCar->has4WD) ? 'does not' : 'does') . ' have 4WD.</p>';
echo '<p>My car ' . (empty($myCar->has4WD) ? 'does not' : 'does') . ' have 4WD.</p>';
echo '<p>Say something: ' . Car::saySomething() . '</p>';
// works but not recommended
echo $myCar::saySomething();
echo $myCar->saySomething();
?>
</body>
</html>
示例2: startEngine
<?php
class Car
{
public $color;
public $make;
public $model;
public $status = 'off';
public function startEngine()
{
// sets the valus of $status in the instance
$this->status = 'running';
}
}
// create an instance of the Car class
$myCar = new Car();
$myCar->color = 'black';
$myCar->make = 'Mercedes';
$myCar->model = '760 Series';
echo '<p>' . $myCar->color . '</p>';
echo '<p>' . $myCar->status . '</p>';
$yourCar = new Car();
$yourCar->color = 'red';
$yourCar->startEngine();
echo '<p>' . $yourCar->status . '</p>';
echo '<p>' . $myCar->status . '</p>';