How to force a static member to be initialized?

Consider: template<typename T, T> struct value { }; template<typename T> struct HasStatics { static int a; // we force this to be initialized typedef value<int&, a> value_user; }; template<typename T> int HasStatics<T>::a = /* whatever side-effect you want */ 0; It’s also possible without introducing any member: template<typename T, T> struct var { enum { … Read more

Error message Strict standards: Non-static method should not be called statically in php

Your methods are missing the static keyword. Change function getInstanceByName($name=””){ to public static function getInstanceByName($name=””){ if you want to call them statically. Note that static methods (and Singletons) are death to testability. Also note that you are doing way too much work in the constructor, especially all that querying shouldn’t be in there. All your … Read more

How to initialize static variables

PHP can’t parse non-trivial expressions in initializers. I prefer to work around this by adding code right after definition of the class: class Foo { static $bar; } Foo::$bar = array(…); or class Foo { private static $bar; static function init() { self::$bar = array(…); } } Foo::init(); PHP 5.6 can handle some expressions now. … Read more