php - 获取未捕获的错误:调用未定义的方法 Vehicles::setPassengerSeats()
问题描述
我收到此错误:
在 C:\xampp\htdocs\practice\vehicle.php:91 中对取消定义方法 Vehicles::setPassengerSeats() 的未捕获错误调用。
我还添加了错误的屏幕截图。请检查并告诉我如何解决?我想我的子类有问题,但我不知道在哪里?
这是我的源代码:
<?php
class Vehicles{
private $noOfVehicles;
private $color;
private $fuel;
private $speed;
public function getNoOfVehicles(){
return $this->noOfMobiles;
}
public function setNoOfVehicles($Vehicles){
$this->noOfMobiles = $Vehicles;
echo "No of Vehicles are: ".$this->noOfVehicles."</br>";
}
public function getColor(){
return $this->color;
}
public function setColor($look){
$this->color = $look;
echo "</br>The Color of Vehicle is: ".$this->color."</br>";
}
public function getFuel(){
return $this->fuel;
}
public function setFuel($petrol){
$this->fuel = $petrol;
echo "</br>The fuel is: ".$this->color."</br>";
}
public function getSpeed(){
return $this->speed;
}
public function setSpeed($vehicleSpeed){
$this->speed = $vehicleSpeed;
echo "</br>The speed of vehicle is: ".$this->speed."</br>";
}
}
class PassengerVehicles extends Vehicles{
private $passengerSeats;
public function getPassengerSeats(){
return $this->passengerSeats;
}
public function setPassengerSeats($seats){
return $this->passengerSeats = $seats;
echo "</br>Passenger Seats are: ".$this->passengerSeats."</br>";
}
}
class TransportationVehicles extends Vehicles{
private $noOfDoors;
private $loadCapacity;
public function getNoOfDoors(){
return $this->noOfDoors;
}
public function setNoOfDoors($doors){
return $this->noOfDoors = $doors;
echo "</br>The No of Doors are: ".$this->noOfDoors."</br>";
}
public function getLoadCapacity(){
return $this->loadCapacity;
}
public function setLoadCapacity($capacity){
return $this->loadCapacity = $capacity;
echo "The Load Capacity is: ".$this->loadCapacity."</br>";
}
}
$VehiclesObj = new Vehicles;
$VehiclesObj->setNoOfVehicles("15");
$VehiclesObj->setColor("Black");
$VehiclesObj->setFuel("5 Litre");
$VehiclesObj->setSpeed("120 km/h");
$VehiclesObj->setPassengerSeats("4");
$VehiclesObj->setNoOfDoors("4");
$VehiclesObj->setLoadCapacity("500 KG");
?>
解决方案
您调用setPassengerSeats
不在另一个类中的方法Vehicles
您应该首先创建实例,然后调用此方法:
$passangerVehicle = new PassengerVehicles;
$passangerVehicle->setPassengerSeats("4");
推荐阅读
- vb.net - 将纬度/经度传递给距离函数时的类型转换问题
- prolog - 协同本体构建与Prolog
- asp.net-core - 使用 ntlm 在 Intranet 站点上进行混合身份验证,并可以更改登录用户
- python - Django Rest 返回 0 字节 zip 文件作为响应
- datetime - 将字符串转换为 xs:dateTime
- tsql - 写入具有基于它的索引和视图的表
- javascript - 调用方法时返回空数组
- java - 使用继承树模型简化数学表达式
- ios - UItableview 行未在 swift4 中与 mapkit 一起显示
- imagemagick - 如何将图像列表中的图像调整为相同大小