本文整理汇总了PHP中Car::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP Car::getName方法的具体用法?PHP Car::getName怎么用?PHP Car::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car::getName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Bike
<?php
include "Models/Bike.php";
include "Models/Car.php";
include "Models/Plane.php";
$minutos = 10;
$vehicle = new Bike();
echo $vehicle->getName() . ': </br>';
echo 'velocidad: ' . $vehicle->speed() . '</br>';
echo 'maximo de pasajeros: ' . $vehicle->maxPassengers() . '</br>';
echo 'distancia: ' . $vehicle->travelDistance($minutos) . '</br> </br>';
$vehicle2 = new Car();
echo $vehicle2->getName() . ': </br>';
echo 'velocidad: ' . $vehicle2->speed() . '</br>';
echo 'maximo de pasajeros: ' . $vehicle2->maxPassengers() . '</br>';
echo 'distancia: ' . $vehicle2->travelDistance($minutos) . '</br> </br>';
$vehicle3 = new Plane();
echo $vehicle3->getName() . ': </br>';
echo 'velocidad: ' . $vehicle3->speed() . '</br>';
echo 'maximo de pasajeros: ' . $vehicle3->maxPassengers() . '</br>';
echo 'distancia: ' . $vehicle3->travelDistance($minutos) . '</br> </br>';
示例2: Plane
$x = new Plane();
$max = $x->maxPassengers();
if ($new_pas <= $max) {
echo "You can travel now";
} else {
$name = $x->getName();
echo "You can not travel on a " . $name . " whit " . $new_pas . " passengers. The number of allowed passengers for the selected transport is " . $max;
}
break;
case '2':
$x = new Car();
$max = $x->maxPassengers();
if ($new_pas <= $max) {
echo "You can travel now";
} else {
$name = $x->getName();
echo "You can not travel on a " . $name . "whit" . $new_pas . "passengers. The number of alllowed passengers for the selected transport is" . $max;
}
break;
case '3':
$x = new Bike();
$max = $x->maxPassengers();
if ($new_pas <= $max) {
echo "You can travel now";
} else {
$name = $x->getName();
echo "You can not travel on a " . $name . "whit" . $new_pas . "passengers. The number of alllowed passengers for the selected transport is" . $max;
}
break;
}
}
示例3: Car
{
return [$a, $b, $a + $b];
}
list($first, $second, $sum) = list_sum(10, 20);
echo "{$first} {$second} {$sum}" . PHP_EOL;
// ref functions
class Car
{
public $name = 'Car';
public function &getName()
{
return $this->name;
}
}
$ferrari = new Car();
$carName =& $ferrari->getName();
// a reference is returned from the function
$refCarName =& $carName;
// second reference for car name
echo $carName . PHP_EOL;
$ferrari->name = "Ferrari";
echo $carName . PHP_EOL;
$refCarName = "Fiat";
echo $carName . PHP_EOL;
// returning types (only available on PHP 7)
/*function sum_type(float $a, float $b): float {
return $a + $b;
}
$result = sum_type(10.56, 55.43);
// returning object
示例4: Car
echo "<h3>" . $harryPotter->getName() . "</h3>";
// Can buy car ?
echo "<p>" . $harryPotter->getName() . " can buy the car?", PHP_EOL;
$bmw2 = clone $bmw;
//Buy car
//$harryPotter->buyCar($bmw);
//Show owned car :
echo "<p>Person's money after the transaction: " . $harryPotter->buyCar($bmw2) . "</p>";
var_dump($bmw2);
echo "buy car:";
var_dump($harryPotter->buyCar($bmw2));
//echo "<p>" .$harryPotter->getName() . "owns". $harryPotter->getOwnedCar()."</p>";
echo "Test aggregation: ";
$bmw->generateObjPerson("David Coperfield", "007", true, 200000);
//($name, $personalNumber, $isMale, $money)
echo "<p>Person: " . $bmw->getName() . "</p>";
echo "<p>Person: " . $bmw->buyCar() . "</p>";
// ---------Nissan sports car
echo "<hr>";
$nissanSport = Car::withPriceandMaxspeed("Nissan", false, "green", 200000, 320);
//$model, $isSportsCar, $color, $price, $maxSpeed
var_dump($nissanSport);
echo "<p> New sports car constructor used: Nissan : " . $nissanSport->getModel() . " </p>";
echo "<p> Sports car? : " . $nissanSport->getIsSportscar() . "</p>";
echo "<p> Sports car speed : " . $nissanSport->getMaxspeed() . "</p>";
$priceNissanforscrap = $nissanSport->calculateCarPriceForScrap(200);
echo "<p> The price for scrap is : " . $priceNissanforscrap . " </p>";
echo "<hr>";
//-------------------------------------------------------------------------------//
//Second Car :Mercedez
$merc = new Car("Voldemor", "mercedez-benz", "220", "silver", false);
示例5: rename
public function rename()
{
//调用父类成员
$this->name = parent::getName() . '2';
}