希望指点错在哪里,应该要如何样改
程序员文章站
2024-02-04 20:13:46
...
希望指点错在哪里,应该要怎么样改?
interface PCI{
function ShowDiveceName();
}
class SoundAdaper implements PCI{
function ShowDiveceName(){
echo "SoundAdaper
";
}
}
class NetworkAdaper implements PCI{
function ShowDiveceName(){
echo"NetworkAdaper
";
}
}
class DisplayAdaper implements PCI{
function ShowDiveceName(){
echo"DisplayAdaper
";
}
}
class Mainboard{
private $PciDevice;
function plug($PciDevice){
$this->PciDevice=$PciDevice;
}
function PCI(){
$this->PciDevice->ShowDeviceName();
}
}
class Engineer{
function Work($Main,$PciDevice){
$Main->plug($PciDevice);
//Fatal error: Call to a member function plug() on a non-object in C:\wamp\www\class_class.php on line 39
//不太明白$Main->plug($PciDevice);这错在哪里
}
}
$sound = new SoundAdaper();
$video = new DisplayAdaper();
$net = new NetworkAdaper();
$main = new MainBoard();
$people = new Engineer();
$people->Work($Main,$SoundAdaper);
$main->PCI();
$people->Work($Main,$DisplayAdaper);
$main->PCI();
$people->Work($Main,$NetworkAdaper);
$main->PCI();
?>
------解决方案--------------------
另外 $SoundAdaper、$DisplayAdaper、$NetworkAdaper 在哪里赋值的?
interface PCI{
function ShowDiveceName();
}
class SoundAdaper implements PCI{
function ShowDiveceName(){
echo "SoundAdaper
";
}
}
class NetworkAdaper implements PCI{
function ShowDiveceName(){
echo"NetworkAdaper
";
}
}
class DisplayAdaper implements PCI{
function ShowDiveceName(){
echo"DisplayAdaper
";
}
}
class Mainboard{
private $PciDevice;
function plug($PciDevice){
$this->PciDevice=$PciDevice;
}
function PCI(){
$this->PciDevice->ShowDeviceName();
}
}
class Engineer{
function Work($Main,$PciDevice){
$Main->plug($PciDevice);
//Fatal error: Call to a member function plug() on a non-object in C:\wamp\www\class_class.php on line 39
//不太明白$Main->plug($PciDevice);这错在哪里
}
}
$sound = new SoundAdaper();
$video = new DisplayAdaper();
$net = new NetworkAdaper();
$main = new MainBoard();
$people = new Engineer();
$people->Work($Main,$SoundAdaper);
$main->PCI();
$people->Work($Main,$DisplayAdaper);
$main->PCI();
$people->Work($Main,$NetworkAdaper);
$main->PCI();
?>
------解决方案--------------------
另外 $SoundAdaper、$DisplayAdaper、$NetworkAdaper 在哪里赋值的?
相关文章
相关视频