这是我的第一个代码&有一个错误:
可捕获的致命错误:传递给 Shop::__construct() 的参数 1 必须是 Generator 的实例,没有给出,在第 7 行的 C:\xampp\htdocs\oop\config.php 中调用并在 C:\xampp\htdocs 中定义\oop\shop.class.php 在第 8 行
第 8 行:
public function __construct(Generator $generator)
我的代码:
class Shop
{
private $generator;
private $vates;
public function __construct(Generator $generator)
{
$this->Generator = $generator;
$this->vates = 'Connected with 250 vates!';
}
public function connect()
{
if ($this->Generator->isDown())
{
echo 'Sorry, the generator is down!';
}
else
{
echo 'Sucessfully', $this->vates;
}
}
}
配置文件:
include("system.class.php");
include("shop.class.php");
$generator = new Generator;
$shop = new Shop;
系统类
class Generator
{
private $power = false;
public function powerUp()
{
$this->power = true;
echo 'You powered up the generator';
}
public function shutDown()
{
$this->power = false;
echo 'The generator slowly shutting down...';
}
public function isDown()
{
return $this->power;
}
}
我做错了什么?谢谢 ;)