Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84602 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58135 invoked from network); 11 Mar 2015 23:21:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Mar 2015 23:21:38 -0000 X-Host-Fingerprint: 91.115.245.126 91-115-245-126.adsl.highway.telekom.at Received: from [91.115.245.126] ([91.115.245.126:9240] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6D/2C-32765-10EC0055 for ; Wed, 11 Mar 2015 18:21:38 -0500 Message-ID: <6D.2C.32765.10EC0055@pb1.pair.com> To: internals@lists.php.net Date: Thu, 12 Mar 2015 00:21:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Posted-By: 91.115.245.126 Subject: static constructor From: mail@deroetzi.de (Johannes Ott) 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