doushouxie7064 2012-09-25 22:04
浏览 17

扩展类php的同名

I am trying to create a php class that will take in data from multiple child classes and display the value at the end

class ManifestBuilder
{

  static $manifest;

  function __construct( )
  {
    $this->get_manifest( );
  }

  function get_manifest( )
  { 
    include 'manifest.php';
    include 'sub1/manifest.php';
    include 'sub2/manifest.php';
    var_dump ( ManifestBuilder::$manifest ); 
  }

  function add_manifest( $var )
  {
    ManifestBuilder::$manifest .= $var;
  }


}

new ManifestBuilder( );

Each child looks like this

class Manifest extends ManifestBuilder 
{

  function __construct( )
  {
    $this->manifest( );
  }

  function manifest( )
  {

    parent::add_manifest( 'manifest1' );

  }

}

new Manifest( );

The problem is that I want to name the class the same on each child so I can easily move them around, but I am getting an error that class names cannot be the same (expected).

How can I solve this? I want to have multiple child classes be able to add to a variable in the parent class.

Thanks.

  • 写回答

1条回答 默认 最新

  • doqrt26664 2012-09-25 22:16
    关注

    You can't. It's as simple as that.

    And it makes sense too. If you need further functionality on the same class, simply refactor it. If you need a child class, extend it.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大