Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84649 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12592 invoked from network); 12 Mar 2015 18:41:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2015 18:41:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@bof.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@bof.de; 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:41461] helo=mars.intermailgate.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2E/04-24603-DBDD1055 for ; Thu, 12 Mar 2015 13:41:03 -0500 Received: (qmail 12275 invoked by uid 1009); 12 Mar 2015 19:40:58 +0100 Received: from 209.85.192.46 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:1(209.85.192.46):. Processed in 0.278492 secs); 12 Mar 2015 18:40:58 -0000 X-Antivirus-MYDOMAIN-Mail-From: php@bof.de via mars X-Antivirus-MYDOMAIN: 1.25-st-qms (Clear:RC:1(209.85.192.46):. Processed in 0.278492 secs Process 12267) Received: from mail-qg0-f46.google.com (gmail@bof.de@209.85.192.46) by mars.intermailgate.com with RC4-SHA encrypted SMTP; 12 Mar 2015 19:40:58 +0100 Received: by qgfi50 with SMTP id i50so20383406qgf.10 for ; Thu, 12 Mar 2015 11:40:56 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.140.135.207 with SMTP id 198mr57077450qhh.71.1426185656967; Thu, 12 Mar 2015 11:40:56 -0700 (PDT) Received: by 10.140.82.198 with HTTP; Thu, 12 Mar 2015 11:40:56 -0700 (PDT) Received: by 10.140.82.198 with HTTP; Thu, 12 Mar 2015 11:40:56 -0700 (PDT) In-Reply-To: <5501D328.9040800@gmail.com> References: <6D.2C.32765.10EC0055@pb1.pair.com> <5500D967.5040800@gmail.com> <13.69.64353.73451055@pb1.pair.com> <5501876C.3020107@gmail.com> <3D.85.42021.3E7A1055@pb1.pair.com> <5501B77D.5010800@gmail.com> <85.D1.24603.247C1055@pb1.pair.com> <5501D328.9040800@gmail.com> Date: Thu, 12 Mar 2015 19:40:56 +0100 Message-ID: To: Rowan Collins Cc: internals Content-Type: multipart/alternative; boundary=001a1135dfa277a7e305111bb973 Subject: Re: [PHP-DEV] static constructor From: php@bof.de (Patrick Schaaf) --001a1135dfa277a7e305111bb973 Content-Type: text/plain; charset=UTF-8 Am 12.03.2015 18:56 schrieb "Rowan Collins" : > > Johannes Ott wrote on 12/03/2015 17:05: > >>>> So doing a null check each time >>>> is a overhead of calculation which can be avoided with this static >>>> constructor pattern. >>> >>> Presumably the engine would need to perform some implicit equivalent of >>> "if ( ! self::$initialised )" on each call to decide if the static >>> constructor needs to be called or not, so the overhead is not completely >>> eliminated. >>> >> Yes you are right but I think it can be done more efficiently inside the >> interpreter using some struct flags then have to parse each time inside >> a coded part in the application. > > Yes, point taken. I don't think such a flag is neccessary at all. Any class. at the moment, comes from one or another file that is included / required. And all of the code in these files outside the class definition, is then immediately executed. The only thing neccessary would be to check, just before that execution begins, which of the new classes have such an initializer method, and then call that, before the execution of the file itself begins. Incidentally that is something that cannot be emulated with the autoloader-does-it approach, because the autoloader can only do that after the include/require is complete - i.e. code within the file will not yet see the class as initialized (in that approach). (I wrote "at the moment" above, because the currently proposed anonymous class thing would need extra thought when the anonymous class has such an initializer method...) best regards Patrick --001a1135dfa277a7e305111bb973--