0

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.

2
  • might consider composition over inheritance,btw did ur ErrorHandler class have $status_page property? Commented Mar 13, 2011 at 17:34
  • Yes $status_pages has been set. So you mean I just initiate all my other classes like ErrorHandler in the construct of my main Application Class? So I don't have to use static functions, right? Commented Mar 14, 2011 at 19:15

1 Answer 1

1

$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.

Sign up to request clarification or add additional context in comments.

2 Comments

If you dont' want to to use it static, you'll have to create an instance of the class with $var = new ClassName();
When I make it static I get the error "Using $this when not in object context". Creating a new instance is not an option I'm afraid (it will reset $status_pages).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.