Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6672935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:34:02+00:00 2026-05-26T03:34:02+00:00

I have a basic MVC setup with helper classes containing utility methods, several of

  • 0

I have a basic MVC setup with helper classes containing utility methods, several of these are likely to be used when loading a view, in both the view itself, the controller and sometimes, but not often, the models. I use autoloading to find the helper files I need, so the class is only ever included once, then, in theory the file shouldn’t get searched/included again, that way I don’t have to put include statements in the script and (i believe) the file isn’t loaded unless the class is used.

My question is what’s likely to be the most efficient way to make calls to these helper classes? Should I make all methods in a given helper static, or maybe use a singleton pattern for the helpers or should I just create a new instance wherever it’s used (e.g. an instance in the view an instance in the controller…) ?

thanks for your input

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:34:03+00:00Added an answer on May 26, 2026 at 3:34 am

    (i believe) the file isn’t loaded unless the class is used.

    Correct. That’s how autoloading works.

    My question is what’s likely to be the most efficient way to make calls to these helper classes?

    Efficient, well, what’s efficient? Maybe using C/C++ and compiling the stuff. Anyway, let’s try:

    Should I make all methods in a given helper static,

    No.

    or maybe use a singleton pattern for the helpers

    No.

    or should I just create a new instance wherever it’s used (e.g. an instance in the view an instance in the controller…) ?

    Yes. If you only use them from time to time, that’s very efficient because you can make use of anything as you see fit.

    In case you use the same object more often, pass it around, inject it into other functions as it’s needed.

    This way you will get the most benefit from autoloading.


    Helper object that can have multiple helper you can pass around even, will autoload on first access (lazy loading):

    class Helper
    {
        private $helpers = array();
        public function __get($name)
        {
            $name = strtolower($name);
            if(!isset($this->helpers[$name]))
            {
                $classname = ucfirst($name).'Helper';
                $this->helpers[$name] = new $classname;
            }
            return $this->helpers[$name];
        }
    }
    
    class Controller
    {
        private $helper;
        public function __construct()
        {
            $this->helper = new Helper();
        }
    
        public function indexAction()
        {
            $ingredients = $this->helper->something->getIngredientsList();
            ....
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic MVC view model with annotations, for example: [Required(ErrorMessage=Your Name Required)]
I am new to MVC and have a grasp of the basic model, but
I have looked at Spring MVC a few times briefly, and got the basic
I have a basic MVC 2 (RC2) site with one base-level controller (Home), and
I am a newbie to ASP.net & MVC 2, and have understood the basic
Does anyone have any basic instructions for setting up a first MVC project in
I have a basic MVC 2 beta app where I am trying to implement
I have basic Single Sign-On working across 2 MVC sites (call them SiteA and
I have a basic Spring MVC controller that looks like this: @Controller public void
I have an MVC 3 site that is working and currently quite basic. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.