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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:57:20+00:00 2026-05-14T06:57:20+00:00

I have found myself doing this in my code to ‘cache’ the work done

  • 0

I have found myself doing this in my code to ‘cache’ the work done when instantiating my Zend_Db_Table models:

if (Zend_Registry::isRegistered('x_table')) {
    $x_table = Zend_Registry::get('x_table');
} else {
    $x_table = new Default_Model_DbTable_X;
    Zend_Registry::set('x_table', $x_table);
}

It bothered me that this method isn’t very DRY and it dawned on me today that a singleton pattern would probably be a better way to do this. Problem is, I’ve never written a singleton class. When I did some web searches, I found some offhand comments about Zend_Db_Table singletons, but no real examples.

I already have meta-data caching configured.

  1. How do I make my Zend_Db_Table models singletons?
  2. Are there pitfalls or downsides?

Edit: My reason for thinking a singleton was the answer is that I thought I could simply have the following calls in my code $x_table = new Default_Model_DbTable_X; and the single instance would be returned if it existed. If this is possible, I would prefer that solution.

  • 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-14T06:57:20+00:00Added an answer on May 14, 2026 at 6:57 am

    Why not just manage the DbTables in some sensible place? If there’s no sensible place, create a DbTableManager class. Something like:

    <?PHP
    class DbTableMgr {
    
      protected $_tables;
    
      public function getTable($classname){
        if ( empty($this->_tables[$name]) ){
          //assuming some things about class names for the sake of brevity elsewhere...
          $classname = 'Default_Model_DbTable_',ucfirst(strtolower($classname));
    
          $this->_tables[$name] = new $classname; 
        }
        return $this->_tables[$name];  
      }
    }
    

    Initialize the manager in your bootstrap and stick it in the registry.

    Then:

    <?PHP
    //in a galaxy far, far, away
    $dbtFoo = Zend_Registry::get('dbtMgr')->getTable('Foo');
    

    So, you lazy-load the dbTable objects, and enforce a singleton-like behavior.

    You could make the above static in various ways, if you wanted to.

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

Sidebar

Related Questions

I am doing some C programming for school and I have found myself reusing
This is my first time using StackOverflow myself. I have found many answers to
Something I have found myself doing often lately is declaring typedefs relevant to a
I have found myself doing a conditional left join several times in R. To
I have found myself designing a language for fun that is a cross between
I am new to fairly new to AS3 and I have found myself needing
I am developing a fairly large C++ support library, and have found myself moving
I have recently found myself becoming more negative about EF and cannot help wondering
I have been playing with NodeJS lately and i found myself stuck with a
Hopefully a simple question although one I have found impossible to answer myself using

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.