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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:57:46+00:00 2026-05-13T07:57:46+00:00

So …. There are obviously many questions that all have been asked about Singletons,

  • 0

So ….

There are obviously many questions that all have been asked about Singletons, Global State Variables, and all that great stuff. My question is,

If Singletons and Globals are So Bad, Why are they used so often?

The following examples are simply ones off the top of my head that I believe are used by a good chunk of people.

I give you a function from CodeIgniter that uses a psuedo-singleton function:

(system\codeigniter\Common.php Line 89)

/**
* Class registry
*
* This function acts as a singleton.  If the requested class does not
* exist it is instantiated and set to a static variable.  If it has
* previously been instantiated the variable is returned.
*
* ......
*/
function &load_class($class, $instantiate = TRUE)
{
    static $objects = array();

    // Does the class exist?  If so, we're done...
    if (isset($objects[$class]))
    {
        return $objects[$class];
    }
  .......
}

By placing every object into a single registry, you can’t use their load_class function to create multiple instances of anything. This is especially inconvenient when you want to use classes as data structures.

Also, because there is only one instance of all those classes, it leads into the argument against Global State. Which leads me to …..

The entire WordPress System, which runs mainly on global variables. All of the data for looping through posts is strewn about in various globals.

(wp-includes\query.php Line 2644)

/**
 * Setup global post data.
 *
 *....
 */
function setup_postdata($post) {
    global $id, $authordata, $day, $currentmonth, $page, $pages, $multipage, $more, $numpages;

    $id = (int) $post->ID;

    $authordata = get_userdata($post->post_author);
    ....
}

These are just two main examples of Frameworks that use Singleton/Globals as the basis for their entire system!

So .. is it just because these systems haven’t caught up to OOP methodology? It just doesn’t make sense when you have so many people telling you not to use Global Variables or Singletons, to make your entire system based on said practices.

There of course is the argument about backwards-compatibility with PHP4. I still think that there were ways to do OOP programming in PHP4, as classes were still available.

  • 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-13T07:57:46+00:00Added an answer on May 13, 2026 at 7:57 am

    Because it’s relatively easy to work with singletons, and working without takes much more detailed planning of your application’s structure. I asked a question about alternatives some time ago, and got interesting answers.

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

Sidebar

Related Questions

so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have been making a wordpress template. i got stuck at some place... the
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
I see that some rss on xml have strange strings. For example, ... is
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
what about this one: I want to format the currentTime displayed by a videoPlayer
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content
I have a form, one of the fields is a select field, with 5
I have a PDB file. Now it has two parts separated by TER. Before

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.