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.
Checkout
Is that your want?
Your could read here about difference between
staticandself– late static binding