将扩展类拆分为不同的文件(php)

时间:2011-05-24 20:35:26

标签: php class class-design abstract-class

SZENARIO

我有一个类作为抽象类的扩展。抽象类加载我的文件&使用方法(link to pastebin for abstract class)进行扩展。

这在我的扩展类中被调用(缩短和简化 - 拼写错误仅在Q代码处):

class Pagination extends Pagination_Base
{
    function __construct()
    {
        // loads the file "first.class.php" in the abstract class
        parent::load_file( 'first' ); 
        // stores the class as object in the abstract class, so we can access the methods and properties
        parent::load_extension( new oxoFirst() );
    }
}

问题/疑问

现在我收到错误“无法重新声明课程{$ classname}”

我想使用我的抽象类,但仍然能够将包含扩展的类移动到单独的文件中。有没有办法做到这一点?

提前致谢!

1 个答案:

答案 0 :(得分:2)

include_once函数中使用include代替load_file