Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116040 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14288 invoked from network); 13 Sep 2021 17:03:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Sep 2021 17:03:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 595B11804C0 for ; Mon, 13 Sep 2021 10:42:16 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 13 Sep 2021 10:42:15 -0700 (PDT) Received: by mail-oi1-f182.google.com with SMTP id j66so3012134oih.12 for ; Mon, 13 Sep 2021 10:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=wAoSqU/U4mZDvxs1d1LjHqnWac3EYmCGeriyeGGA8ZE=; b=w6vQLXpSoQdxH/7VLOyTXZkO+Hg9ttNoL9m6g6ztH4zVKrS/10VEHPRNSE3JdLC2Bk aM19skUI0u1RPLD6BBcNezwdgMa0EyeeLWKxcHwUJXcQIiPzNC+eyyFCJSHn/JgafhoV SdHqStxL5rTAsZkGLKpWJ+kZhfyXmrnaSIBk9pHEwBtPh/YMLNHVowMsVzwhB/c7MCXt aevsYKSXlNIi3JW7HW1BCsJpgtAl/L15hDnalGe7JKk1r1jx8uTYr+dYawfz39d30keQ C9yT1X7JBNLFUl7b+c1mOYVL31vqhTBxlTAlYRhGeEFpJD1I5vtZSIH1xIaOjt39xUih PXjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=wAoSqU/U4mZDvxs1d1LjHqnWac3EYmCGeriyeGGA8ZE=; b=8RaOynk0TmXQpFCpjBmQIQ0RlOZaUZW62HpiCgT9CIoWoMkVPBwP4B3HuEfdkOJSn5 XTgwKr0necz2lnmI78pR/UFpmKFSVJSeRZDrIsKOzerEaQwZYkPrKHBiMnu7mRaASJdg G73PYJOT5ZnQufTcwXc5RWQgYO8T175Uys4fScRoiyw0yd4hWb2Vm0H50N0Rz2Mm/g/z KGds5c0jIQsK00eYT2yUbmdrM7a8I2XoIM3eyUPjKFdPNbIc6uT0tnkYMJPbqccjEP7k 2Uh8NTHucpA+y2xGA8bfuN7ZZDibSIC83waq16PPhAXzcVS+b/lfVLNqy92L0+6hyyn6 lcUw== X-Gm-Message-State: AOAM533QHC8nokJrwzcICsP5hy37pwg3XsCjPMQc8WkymGgF860OQ6YQ rW0DkkdaYdH9gxmrLogYhZJ5Og== X-Google-Smtp-Source: ABdhPJw4PmVYuPxckXru340S7nGLdkdx0dpFXhrkk7dTVuZt4R7loRh9XFy9ANAatQtzmUmP8IY0Xw== X-Received: by 2002:a05:6808:220c:: with SMTP id bd12mr8997839oib.13.1631554932016; Mon, 13 Sep 2021 10:42:12 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id t9sm1830910oie.20.2021.09.13.10.42.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Sep 2021 10:42:10 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) In-Reply-To: Date: Mon, 13 Sep 2021 13:42:09 -0400 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <5D04C5F7-D191-48E9-B3E4-EBDD7E862560@newclarity.net> References: <538C20B2-3491-49DE-BCC0-47F43A51B98F@newclarity.net> To: Rowan Tommins X-Mailer: Apple Mail (2.3608.120.23.2.7) Subject: Re: [PHP-DEV] Class static initialization block From: mike@newclarity.net (Mike Schinkel) > On Sep 13, 2021, at 12:26 PM, Rowan Tommins = wrote: >=20 >> 2.) Make the initialization function private. >=20 > I'm not sure how that would work: a private constructor means that it = has to be explicitly called from within the same class, but a static = initialiser would be called by the engine, before the class scope even = existed. I think we are getting in the weeds here and loosing sight of the = desired outcome. Currently it is not possible for a developer to disallow calling a class = initialization method from outside of the class. However that would end = up being achieved =E2=80=94 via private methods, protected methods, or = even voodoo =E2=80=94 those details are unimportant to ultimately = disallowing the calling of initialization code from outside the class. > =46rom your link, it seems that C# restricts them much more than = methods or constructors: >>=20 >> A static constructor doesn't take access modifiers or have = parameters. >> A class or struct can only have one static constructor. >> Static constructors cannot be inherited or overloaded. >> A static constructor cannot be called directly and is only meant >> to be called by the common language runtime (CLR). It is invoked >> automatically. Those all sound like they would be appropriate restrictions for PHP too. > Apparently, the JS implementation does allow multiple static = initialiser blocks in one class, which are simply processed in order. = But JS classes are weird creations, implemented as a complex sugar on = top of a classless object system, so may not be the best point of = reference for PHP, whose object system much more closely resembles Java = or C#. I did not reference JS =E2=80=94 I only referenced Java and C# =E2=80=94 = so JS' approach was not part of my argument. -Mike=