正在创建具有相同父类的2个子类的实例


Creating instances of 2 child classes with the same parent

我基本上有两个子类,它们有相同的父类。

我想做的是在一个脚本中创建两个类的实例,以便访问它们的一些独特功能,我对这个主题很生疏,但似乎这是不可能的。

我得到错误Fatal error: Cannot redeclare class MWS

我想知道解决这个问题的正确方法是什么?

下面是我的类结构的一个例子

父类

class MWS{
   funcion MWS(){}
}

子类

require_once('mws.php');
class MWS_Orders extends MWS{
   function MWS_Orders(){}
}

子类

require_once('mws.php');
class MWS_Feed extends MWS{
    function MWS_Feed(){}
}

index.php

require_once('mws_feed.php');
require_once('mws_orders.php');
$feed = new MWS_Feed();
$orders = new MWS_Orders();

将父类的声明放在它自己的文件中,并将require_once()放在该文件中。不要在每个子类文件中声明父类,也不要使用require()而不是require_once()