2

My question is what is the best way in terms of performance. For example in the application bootstrap process i have a class

<?php 
class Application
{
    public function __construct()
    {
        $this->setErrorHandler();
        $this->setDatabase();
        $this->sessionHandler();
        $this->disptachRequest();
    }

}
$app = new Application;

Is this a good approach or i should call these methods separately from the variable that holds the object?

I have set those function to private actually that is why i am calling them in constructor. Need guidance if this is good or bad?

2
  • Do all of those methods really take no arguments, or did you just leave them out to simplify the code for the question? Commented Aug 7, 2015 at 21:58
  • umm as of yet they are fine without arguments. Commented Aug 7, 2015 at 22:01

1 Answer 1

1

There is nothing inherently bad in it.

For performance, the question is, if all the calls are necessary in all cases. if not, you could defer them and execute them only if needed (this is called lazy loading)

For proper object oriented design the question is if the Application class and all its methods serve a common single responsibility. If not, break it down into smaller classes.

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

Comments

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.