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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:51:59+00:00 2026-05-13T11:51:59+00:00

Is the Registry design pattern a good solution for this in PHP? For a

  • 0

Is the Registry design pattern a good solution for this in PHP?

For a social network site (facebook, myspace).

let’s say I have a Database class which creates a single DB connection and lets me do DB stuff and a Sessions class which lets me handle sessions as well as a Cache class which lets me cache items and retrieve them. SO that is 3 main classes that I will need to be able to access on every page of my site. After reviewing the Registry Pattern for the past hour, I am thinking that it is the perfect solution maybe. I can store my Database, Session, and Cache objects into a registry Object and then Inject the Registry object into every page or every other class and have access to my database, sessions, and cache.

Before this I was using a singleton pattern so I would have to call my singleton method for all 3 of my MAIN classes inside of every page or other class.

So I am just wondering is there any downfalls of using the Registry class? 1 that I can see is it seems it may be harder to see what classes depend on which other classes and such. Other then that it seems like a great solution for this, also I saw another post on here of a user’s registry class where they were storing setting in the registry an having access to them in all the other classes that the registry Object is passed into, I am sure I will find a good use for that feature as well.

So the only question here is am I missing something or did I just hot the lotto?


UPDATE

Also if using a registry to store objects in, should I do something like this…

$this->session = $registry->getObject('session');

or this instead

$this->registry->session = $registry->getObject('session');

The second method seems like it would maybe be easiar to understand where the object came from?

  • 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-13T11:51:59+00:00Added an answer on May 13, 2026 at 11:51 am

    You mean a registry of Singletons, right? If so, it sounds like all you really want is access to three global objects everywhere, but contained inside another object.

    So if you wrote cache.php, sessions.php, and database.php, which define the classes Cache, Sessions, and Database, you want to contain them all inside a Registry object defined in registry.php.

    First of all, it’s great to control the ORDER of instantiation this way. It’s better than simply doing a require_once of cache.php, sessions.php, and database.php, and inside of them you define not only the class but the single global instance of it. That controls the ORDER of instantiation by how you include/require it. Kind of sleazy. Better to have your Registry object, that when it gets created and becomes a $registry global, first thing is does is control the creation of your globals in the order and how you want.

    Second of all, it’s great to have a single Registry.php that has a single $registry global. Defining globals here and there over various files gets hard to manage.

    Now that I’ve agreed with you, I pose an important question to you. How do you see these being different:

    $registry->getObject('session');
    $registry->getObject('database');
    $registry->getObject('cache');
    

    versus:

    $registry->getSession ();
    $registry->getDatabase ();
    $registry->getCache ();
    

    Personally, I like the latter. You aren’t using a string “session” to refer to a Session object, obtained through a super-generic getObject. Instead, you are using getSession() to get a Session. It reads better.

    Your registry, after all, knows all about the three globals, it creates them explicitly, so it’s already locked into a single purpose. Adding concrete methods also tied to its single purpose isn’t “weak” or “bad”. Instead, I think it’s less code and easier on the eyeballs.

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

Sidebar

Related Questions

I have a registry value which is stored as a binary value (REG_BINARY) holding
I am working with PHP classes and objects now. In this question the names
If i want to develop a registry-like System for Linux, which Windows Registry design
Where is a reliable registry key to find install location of Excel 2007?
There was a registry fix for Visual Studio 2005 to prevent it from checking
I want to set registry keys in following way if OS is Vista then
In the Windows registry, how does CurrentControlSet differ from ControlSet001 and ControlSet002 ? Which
I know there is a registry key indicating the install directory, but I don't
Given the key for some registry value (e.g. HKEY_LOCAL_MACHINE\blah\blah\blah\foo) how can I: Safely determine
We needed to monitor all processes Registry calls/File Sytem calls/Process creations in the system

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.