使用另一个类的函数

时间:2011-03-13 16:48:20

标签: php oop inheritance

我只是从OOP开始(对我感到羞耻),所以请对我温柔。

我有一个ErrorHandler类,它从我的主Application类中调用一个函数来包含一个错误页面。 所以我在ErrorHandler类的函数中使用Application::status_page( $type );

这就是status_page函数的样子(它是包含各种自定义消息的函数):

public function status_page( $page )
{
    // Include the status page that has been set in the routes
    include( STATUS_PAGE_DIR . $this->status_pages[$page] . '.html' );
}

我现在得到一个Undefined property: ErrorHandler::$status_pages,这对我来说是完全的。但解决这个问题的最佳方法是什么?也许让ErrorHandler类扩展主Application类?

我希望我很清楚,并提前感谢您的回答。

1 个答案:

答案 0 :(得分:1)

$ status_pages必须在类的标题中定义

另外,您必须将该函数声明为

public static function status_page($page)

如果你想这样使用它。