Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84650 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15184 invoked from network); 12 Mar 2015 19:12:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2015 19:12:59 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.213.41 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.213.41 mail-yh0-f41.google.com Received: from [209.85.213.41] ([209.85.213.41:37794] helo=mail-yh0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/74-24603-935E1055 for ; Thu, 12 Mar 2015 14:12:58 -0500 Received: by yhoa41 with SMTP id a41so9382965yho.4 for ; Thu, 12 Mar 2015 12:12:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=LSzQiC2fBspqXoHXDJd2LQoPd6KTZwIDewicLD2yxns=; b=J6Xo9Qj9GSMCsMbzz5VksIIgG0Z6yT3aI/zLAUFYUOp6CuyHUZTpq7xAWOra9YZN6l k1umSPqBRXxFDAn7bNgk8MvGiI9ZhxfpySivZxft1aU54ELSaa2LKCx+AfRE+Tx7ISW4 Vc9lxwpna8HOtlm2mMG+okOCmKkLC/99K7cPUdurmJYA9Ft+F53J1/YK4gHxC4FPq5Kd vaaEnvL48J5XX6q54plaS/38pAp+v3FtvmGNN9Kl4QmW9eUGUPGm4paquxtNsggPvkKE 5Y9fqU03CbSb6Yoe3QqfVuMynA/UCWeSXNnKOYtOEb8ahzBGDCfQdovfZK5McjuOzXG7 Qc+w== X-Gm-Message-State: ALoCoQkgMfY6wnVlhx4FnST+ydfwk2j4okH4JcO8xTK020o4GRx4nXCnMdikmEoQye9YTcfDZgVB MIME-Version: 1.0 X-Received: by 10.170.90.70 with SMTP id h67mr48889926yka.46.1426187574383; Thu, 12 Mar 2015 12:12:54 -0700 (PDT) Received: by 10.170.71.86 with HTTP; Thu, 12 Mar 2015 12:12:54 -0700 (PDT) X-Originating-IP: [78.147.4.32] In-Reply-To: <1806447.6ZrGY6hLx0@rofl> References: <6D.2C.32765.10EC0055@pb1.pair.com> <5500D967.5040800@gmail.com> <1806447.6ZrGY6hLx0@rofl> Date: Thu, 12 Mar 2015 19:12:54 +0000 Message-ID: To: Patrick Schaaf Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] static constructor From: danack@basereality.com (Dan Ackroyd) Patrick Schaaf wrote: > But that has proven, in the past, a fountain of joy wrt. > placement, with variations needed for APC and opcache, and general frustration > all around. Is there a bug report for the problems? OPCache shouldn't have side-effects on the code. cheers Dan On 12 March 2015 at 08:40, Patrick Schaaf wrote: > On Thursday 12 March 2015 00:10:15 Rowan Collins wrote: >> On 11/03/2015 23:21, 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 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... > > It's useful everywhere you now have more than one method starting > > if (!static::$is_initialized) static::initialize_me(); > > Some examples from our codebase: > > - a session wrapper class, hiding $_SESSION behind setter/getter methods, > where the static class initialization determines which cookie to use, > depending on some global feature flags, and which session backend to use, > depending on current availability. (main purpose, apart from clean calling > side code just using the setters/getters, is to get the lazy_write > functionality Yasuo tried to introduce recently) > > - computation of some class properties from others, like doing an array_flip > on one to get a reverse mapping. > > - definition of computed constants, in various places. Partly obsolete now > that class constants support constant expressions, but needed as soon as these > are not really constant. > > - setting up some class properties used by various methods, that should depend > on some global feature flags (defined by the users of the class, usually > toplevel scripts) > > - invariant checks on subclasses, in various places, where concrete subclasses > set up some static properties of a configuration nature, and I want to make > sure in the base class, as early as possible, that the values are consistent > and make sense, avoiding checks spread all over the place in various methods. > > Of course, most of this could be done by code outside the class definition, in > the same file. But that has proven, in the past, a fountain of joy wrt. > placement, with variations needed for APC and opcache, and general frustration > all around. > > best regards > Patrick > > > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >