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

  • SEARCH
  • Home
  • 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 7030613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:41:39+00:00 2026-05-28T00:41:39+00:00

Possible Duplicate: Who needs singletons? I always write with respect to best practice ,

  • 0

Possible Duplicate:
Who needs singletons?

I always write with respect to best practice, but I also want to understand why a given thing is a best practice.

I’ve read on in an article (I unfortunately don’t remember) that singleton classes are prefered to be instantiated, rather than being made with static functions and accessed with the scope resolution operator (::). So if I have a class that contains all my tools to validate, in short:

class validate {
    private function __construct(){}
    public static function email($input){
        return true;
    }
}

I’ve been told this is considered bad practice (or at least warned against), because of such things as the garbage collector and maintenance. So what the critiques of the “singleton class as static methods” wants, is that I instantiate a class I’m 100% certain I will only ever instantiate once. To me it seems like doing “double work”, because it’s all ready there. What am I missing?

What’s the view on the matter? Of course it’s not a life and death issue, but one might as well do a thing the right way, if the option is there 🙂

  • 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-28T00:41:40+00:00Added an answer on May 28, 2026 at 12:41 am

    An example singleton classes in php:
    Creating the Singleton design pattern in PHP5 : Ans 1 :
    Creating the Singleton design pattern in PHP5 : Ans 2 :

    Singleton is considered "bad practice".

    Mainly because of this: How is testing the registry pattern or singleton hard in PHP?

    • why are singleton bad?

    • why singletons are evil?

    • A good approach: Dependency Injection

    • Presentation on reusability: Decouple your PHP code for reusability

    • Do you need a dependency injection container

    • Static methods vs singletons choose neither

    • The Clean Code Talks – "Global State and Singletons"

    • Inversion of Control Containers and the Dependency Injection pattern

    Wanna read more? :

    • What are the disadvantages of using a PHP database class as a singleton?

    • Database abstraction class design using PHP PDO

    • Would singleton be a good design pattern for a microblogging site?

    • Modifying a class to encapsulate instead of inherit

    • How to access an object from another class?

    • Testing Code That Uses Singletons

    A Singleton decision diagram (source):

    Singleton Decision Diagram

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

Sidebar

Related Questions

Possible Duplicate: C# 'var' keyword versus explicitly defined variables EDIT: For those who are
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: Interview Q: given an array of numbers, return array of products of
Possible Duplicates: script to tell me who, and how many users, are online Best
Possible Duplicate: PHP: Check who had read sent email? I'm writing a tool in
Possible Duplicate: Protected methods in objective-c I am a Java developer who is starting
Possible Duplicate: WebClient vs. HttpWebRequest/HttpWebResponse I can't guess who is better HttpWebRequest or webclient
Possible Duplicate: Querying Users who 'like' my Facebook Page Currently all the solutions on
Possible Duplicate: undef - Why would you want to undefine a method in ruby?
Possible Duplicate: How to know who clicked the Facebook “Like” button on my site?

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.