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 651561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:10:31+00:00 2026-05-13T22:10:31+00:00

I have am working on a web application that makes use of helper classes.

  • 0

I have am working on a web application that makes use of helper classes. These classes hold functions to various operation such as form handling.

Sometimes I need these classes at more than one spot in my application, The way I do it now is to make a new Object. I can’t pass the variable, this will be too much work.

I was wondering of using singleton classes for this. This way I am sure only one instance is running at a time.

My question however is when I use this pattern, should I make a singleton class for all the objects, this would b a lot of code replication.

Could I instead make a super class of superHelper, which is a singleton class, and then let every helper extend it.

Would this sort of set up work, or is there another alternative?

And if it works, does someone have any suggestions on how to code such a superHelper class.

Thank you guys

  • 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-13T22:10:31+00:00Added an answer on May 13, 2026 at 10:10 pm

    I can’t pass the variable, this will be too much work.

    Are you sure though? People tend to overestimate the effort of passing around dependencies. If you do it in the constructor, it’s usually fairly simple to do.

    That said, you can put shared functionality in the global scope, in different ways in php. The simplest is to use a global function. Eg. a function that doesn’t belong to any class. Another option is to use a static class method. These two a very similar; except for their syntax, they essentially have the same properties. A slightly looser coupled solution is to put the functionality as a method on an (abstract) base class, that your concrete class extends from. This shares the functionality between all child classes.

    Common for the above-mentioned solutions is that they have a compile time coupling. You can’t change the dependency at run time, which makes your application rather rigid. Their main benefit is the low level of complexity they carry.

    If you want a looser coupled application, you can try to replace the hard dependency with a variable, to give a level of indirection. The simples is to create an object and make this shared globally throughout the application. There are a number of ways to do this in PHP, such as a singleton or simply a variable in the global scope (You can access this with the global keyword, or through the $GLOBALS array).

    While global variables offer a level of indirection, they also tend to introduce a lot of complexity, since they make it very hard to figure out which parts of the application that depends on each other. For this reason, they are often avoided by experienced programmers. This is especially true if the variable has state; The problem is less prevalent if the shared object is stateless.

    The only way to avoid the perils of global variables, is to use local variables instead. Eg. To pass the dependencies around. This can be a bit of a hassle, but in my experience it’s often not as big a problem as it’s made out to be. At least, the benefits often outweigh the problems. That said, there are techniques to easy the pain; Notably dependency injection containers, which are automatic factories that take care of all the wiring for you. They come with their own level of complexity though, but for larger applications they can certainly be a good solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that I'm working on for work and its not
I need to have a working web browser in a fullscreen Direct3D application. For
I am working on a web application and I have run into the following
I have created a Web Application in asp.net 2.0. which is working fine on
I'm working on a large website project that makes heavy use of in-page graphing
I have an existing ASP.NET web application that I'm converting to MVC 1.0. The
I'm working on a demo that makes use of Spring.NET IoC capability in ASP.NET
I'm working through Practical Web 2.0 Appications currently and have hit a bit of
I have been working on a web services related project for about the last
I've been working with web start for a couple years now and have experience

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.