Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84648 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8956 invoked from network); 12 Mar 2015 17:56:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2015 17:56:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.175 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.175 mail-wi0-f175.google.com Received: from [209.85.212.175] ([209.85.212.175:37618] helo=mail-wi0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B1/83-24603-053D1055 for ; Thu, 12 Mar 2015 12:56:34 -0500 Received: by widem10 with SMTP id em10so35105697wid.2 for ; Thu, 12 Mar 2015 10:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=FbeEFPF6C5BET1cyPy0Nrd/dX/YIDFJIYmQDhGbCCiE=; b=hDk855BJO9333gyWdaPlT5jLBOvfUKcTq9tXXGIx9vzdWZSVrs6tojzBM0E2mPm8xy CT4ZVhwZKpbpVpPPYWvhKOPoSWmpooBMuPt8NBXqjEFP/NykR3n2EtKaeIHxNfoe2H9O tRqS7td7oapSbxv6nAgYL7p9iAaBbncgIvlsBSCiymR6NbNkFjFvBFa6JOI8+IT8e/vS +yS138/hIXeaFvuPMjcWKTHxYvwzZWCuGxU1PMGPjdmeU7Jq7Q17cCA7Jq1Pkas8E45u GnVTiPlijvPNXYRe0Z+nETuWRXAvuLF8ithfxhrDYORIuxZiITCUJMK1r+6Wiq9VCgk2 qv+Q== X-Received: by 10.180.126.69 with SMTP id mw5mr136237097wib.12.1426182990368; Thu, 12 Mar 2015 10:56:30 -0700 (PDT) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id vq9sm11106377wjc.6.2015.03.12.10.56.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Mar 2015 10:56:29 -0700 (PDT) Message-ID: <5501D328.9040800@gmail.com> Date: Thu, 12 Mar 2015 17:55:52 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: internals@lists.php.net 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> In-Reply-To: <85.D1.24603.247C1055@pb1.pair.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] static constructor From: rowan.collins@gmail.com (Rowan Collins) Johannes Ott wrote on 12/03/2015 17:05: > Am 12.03.2015 um 16:57 schrieb Rowan Collins: >> Johannes Ott wrote on 12/03/2015 14:51: >>> That is nearly like initializing a class constant, but in my opinion a >>> constant should not have a "complex" algorithm (For example conditions >>> or read from filesystem). That should be encapsulated inside a proper >>> method body. >> I agree, but as such, I think that method should be called somewhere by >> the code, even if only by a DI container, not happen automagically and >> slurp in data from global state. >> > It is called somewhere in the code namely inside the static constructor :D What I meant is that it is not executed by any piece of code the user writes, but directly by the engine based on a magic hook. >>> 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. >> Incidentally, note that a recent RFC to add the ability to declare a >> class as static failed by 12 votes to 5 - >> https://wiki.php.net/rfc/abstract_final_class - and much of the >> discussion was around static implementations being generally inferior to >> instances, so I'm not alone in challenging designs that rely on them. >> > I will check the rfc later but "static class" sounds strange. Basically, all your examples imply classes that consist only of static members - they're not using static helpers to create instances, they're using them *instead of* instances. This was what was mean by "static class" in that proposal. Personally, I was in favour of that, since I think such classes do exist, and a syntax for declaring them would be useful, but the most common argument against was that we should be finding ways for people to not need such classes, rather than supporting them better. This proposal sounds like it's adding facilities to classes that belong on objects, or ... somewhere else. Regards, -- Rowan Collins [IMSoP]