Re: static constructor

From: Date: Thu, 12 Mar 2015 04:17:30 +0000
Subject: Re: static constructor
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-84609@lists.php.net to get a copy of this message
On Wed, Mar 11, 2015 at 6:10 PM, Rowan Collins <rowan.collins@gmail.com> wrote: > On 11/03/2015 23:21, Johannes Ott wrote: >> >> 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. > > > Can you give an example use case for when this would be useful? I'm > struggling to think of one for which there isn't already an established > coding pattern... Notably, user-land enums. You don't want public constructors because you don't want it instantiated except for each enum property. You also need it to run on class creation, not afterwards. I think we'd be better off adding language-level enums than static constructors though.

« previous php.internals (#84609) next »