Jesse
Jesse

Reputation: 479

Using a function from another class

I'm just starting with OOP (shame on me), so be gentle with me.

I have an ErrorHandler class that calls a function from my main Application class to include an error page. So I'm using Application::status_page( $type ); in a function in the ErrorHandler class.

This is how the status_page function looks like (it's a function to include all kinds of custom messages):

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' );
}

I'm now getting an Undefined property: ErrorHandler::$status_pages which makes total sence to me. But what is the best way to solve this? Maybe let the ErrorHandler class extend the main Application class?

I hope I was clear and thanks in advance for answering.

Upvotes: 0

Views: 86

Answers (1)

uadnal
uadnal

Reputation: 11435

$status_pages must be defined in the header of the class

also, you must declare the function as

public static function status_page($page)

if you want to use it like that.

Upvotes: 1

Related Questions