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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:48:34+00:00 2026-05-22T02:48:34+00:00

I have a singleton class used to initialise error_handling. The class as is takes

  • 0

I have a singleton class used to initialise error_handling.

The class as is takes a Zend_Config object and optional $appMode in parameter, to allow overriding the defined APPMODE constant when testing this class. All is fine if I create the object with non-static properties, but initialising a static property does not work the way I expected when calling the usual getInstance().

class ErrorHandling{

  private static $instance;
  private static $_appMode;  // not initialised in returned instance
  private $_errorConfig;

 private function __construct(Zend_Config $config, $appMode = null){

   $this->_errorConfig = $config;

   if(isset($appMode)){
       static::$_appMode = $appMode;
   }else{
         static::$_appMode = APPMODE;
   }  
 }

 private final function  __clone(){}

 public static function getInstance(Zend_config $config, $appMode = null){
     if(! (static::$instance instanceof self)){
         static::$instance = new static($config, $appMode);
     } 
     return static::$instance;
 }
}

Not that I really need $_appMode to be static at all, I declared it private and moved on, but I am still wondering if one can initialise static properties from a static function call. If I REALLY needed static $_appMode, I could probably create the object and set the value afterwards with a setter method but this doesn’t “feel” as being the best way to do this.

  • 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-22T02:48:34+00:00Added an answer on May 22, 2026 at 2:48 am

    Checkout

    <?
    
    class ErrorHandling{
    
      private static $instance;
      private static $_appMode;  // not initialised in returned instance
      private $_errorConfig;
    
     private function __construct(array $config, $appMode = null){
    
       $this->_errorConfig = $config;
    
       if(isset($appMode)){
           self::$_appMode = $appMode;
       }else{
             self::$_appMode = APPMODE;
       }  
     }
    
     private final function  __clone(){}
    
     public static function getInstance(array $config, $appMode = null){
         if(! (self::$instance instanceof self)){
             self::$instance = new ErrorHandling($config, $appMode);
         } 
         return self::$instance;
     }
    
     public static function getAppMode() {
        return self::$_appMode;
     }
    } 
    
    $e = ErrorHandling::getInstance(array('dev' => true), -255);
    var_dump($e, ErrorHandling::getAppMode());
    

    Is that your want?

    Your could read here about difference between static and self– late static binding

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

Sidebar

Related Questions

I have a C# singleton class that multiple classes use. Is access through Instance
So I have the following: public class Singleton { private Singleton(){} public static readonly
I have a co-worker that swears by //in a singleton Constants class public static
I was confused when I first started to see anti-singleton commentary. I have used
I have some class it is a singleton we have this class in already
I have a class representing a set of values that will be used as
I have a Windows Mobile 6.5 (.net cf 3.5) that uses a singleton class
In the Ruby Standard Library we have the Singleton class: http://ruby-doc.org/stdlib/libdoc/singleton/rdoc/index.html We can make
i have dialogbox as a singleton class and on that dialog box i hv
I have a specific class in my project that used for load and hold

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.