Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84612 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13356 invoked from network); 12 Mar 2015 08:15:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2015 08:15:04 -0000 Authentication-Results: pb1.pair.com header.from=php@bof.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@bof.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain bof.de designates 80.242.145.70 as permitted sender) X-PHP-List-Original-Sender: php@bof.de X-Host-Fingerprint: 80.242.145.70 mars.intermailgate.com Received: from [80.242.145.70] ([80.242.145.70:55310] helo=mars.intermailgate.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 50/E7-64353-50B41055 for ; Thu, 12 Mar 2015 03:15:03 -0500 Received: (qmail 534 invoked by uid 1009); 12 Mar 2015 09:14:58 +0100 Received: from 192.109.53.146 by mars (envelope-from , uid 89) with qmail-scanner-1.25-st-qms (clamdscan: 0.96.2/20182. spamassassin: 3.3.1. perlscan: 1.25-st-qms. Clear:RC:0(192.109.53.146):SA:0(1.3/8.0):. Processed in 0.38512 secs); 12 Mar 2015 08:14:58 -0000 X-Spam-Status: No, hits=1.3 required=8.0 X-Spam-Level: + X-Antivirus-MYDOMAIN-Mail-From: php@bof.de via mars X-Antivirus-MYDOMAIN: 1.25-st-qms (Clear:RC:0(192.109.53.146):SA:0(1.3/8.0):. Processed in 0.38512 secs Process 522) Received: from unknown (HELO rofl.localnet) (gmail@bof.de@192.109.53.146) by mars.intermailgate.com with AES256-SHA encrypted SMTP; 12 Mar 2015 09:14:57 +0100 To: internals@lists.php.net Cc: Johannes Ott Date: Thu, 12 Mar 2015 09:14:56 +0100 Message-ID: <6023256.6UxfYvu8RT@rofl> User-Agent: KMail/4.14.4 (Linux/3.19.0-5.g748552c-desktop; KDE/4.14.4; x86_64; ; ) In-Reply-To: <6D.2C.32765.10EC0055@pb1.pair.com> References: <6D.2C.32765.10EC0055@pb1.pair.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Subject: Re: [PHP-DEV] static constructor From: php@bof.de (Patrick Schaaf) On Thursday 12 March 2015 00:21:34 Johannes Ott wrote: > > 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 t= he > class. We are doing this in our private codebase, implemented as a feature of = our=20 autoloader: after having loaded a class, check whether it has a static = method=20 called 'init=A7class()', and call that. At the moment, 63 of our 397 classes have that, so it's definitely a su= ccess=20 for us. One issue to think about, is whether to call that function when it's ju= st=20 inherited. We do, and in several places, then check if (get_called_clas= s() =3D=3D=20 __CLASS__). It's a bit tedious in places, but in other places it permit= s=20 setting up of subclass static::$properties from a shared baseclass init= ializer=20 method. In principle none of that is neccessary, because one can put code outsi= de the=20 class definition. One more line to write. In practise, it's a bit annoy= ing, as=20 it must go after the whole class definition, or it breaks for subclasse= s in=20 funny ways when the parent class is not already defined... Something like your version 2 proposal, a new __magic method, would be = my=20 prefered choice, too. best regards Patrick