static constructor

From: Date: Wed, 11 Mar 2015 23:21:34 +0000
Subject: static constructor
Groups: php.internals 
Request: Send a blank email to internals+get-84602@lists.php.net to get a copy of this message
So now I want to do my first own proposal for a new function in PHP and I hope doing it right with starting a discussion here first. The purpose of this suggestion is to introduce a static constructor, which is called before the first call to class either static or non-static to initialize some static properties which are needed by the class. I think about two different possible syntax to realize that purpose: Version 1 (similar to Java): class A { private static $var; static { //Do some code here to initialize self::$var; } } Version 2 (a new magic method): class B { private static $var; private static function __static() { //Do some code here to initialize self::$var; } } My prefered code would be version 2 at the moment. Looking forward to your feedback, -- DerOetzi

« previous php.internals (#84602) next »