Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123628 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 5607F1A009C for ; Sun, 16 Jun 2024 10:19:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718533212; bh=o3UtBX/PEqyIYdZ1X7llh+JZx4HfoDLhHO97FznRyBg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EtclzpaUbRgbS7WYI+eDnEpFiC6p6GHuUzN7uqzofUXsEwVhImgaQwJl1WZA+YtFY uR04LiQ3W5+JOKNWCG1qo4NiIzObliiqGjm9KA+qyEtvoXYu4edWjYZBM0jZn8clW+ zot1EDJ5C2j1e5nu0fjpx5J7a05qnkTyt41GOALnYRh3pDEwX6k5k9fVvrMx+N7AW7 mJMZ9OuzwBPzTn8bFOXij47Mj0dnRZoer2IvX01b8p5xa0YxI+fnszTPv2WerRjl22 jX3jWbXfOR3Gc0Gn6SW+UITMrkP8WdktEI12ry7mZ93VrnDWsDDrZtlAvQfF8sFsyC 9DTxcbyvb+gWg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 57B1A180666 for ; Sun, 16 Jun 2024 10:20:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-ua1-f44.google.com (mail-ua1-f44.google.com [209.85.222.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 16 Jun 2024 10:20:10 +0000 (UTC) Received: by mail-ua1-f44.google.com with SMTP id a1e0cc1a2514c-80b8a8b06b9so915255241.2 for ; Sun, 16 Jun 2024 03:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718533139; x=1719137939; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=o3UtBX/PEqyIYdZ1X7llh+JZx4HfoDLhHO97FznRyBg=; b=A3w4MabUbgrXtxgu4WYt01EEvqdNLiT/UBmO97XAnUWTAUAv5D5Aro8oPVtoQSV/Nl dREfv3UxuXLBf2Ckp6oLHCSQKPu5JHLXuKfOdthTenUGfq9hx/9rNN5uAzrBbq75zfFY nzlWUdsNwNEJ9iaJA4rOAU9agNxOzc6G4JLu9SU2px27QsnuLxXHqGB3be0uxcyoG+f/ 0xFyqdbxn82C1GXVwoqKSmEi1xvIY4epZ/Vz9VUXc/roi1ZqdoNX9TKU0frdUG1FDKv/ hUnfeQdHJIYOWQhoz5/1BdtRQu4TwJd5r4QMnsZPWCJL8Ks6X/7TQ0yDez6ozfFSqSAa 8SUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718533139; x=1719137939; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=o3UtBX/PEqyIYdZ1X7llh+JZx4HfoDLhHO97FznRyBg=; b=f52vEJ+13tOdwNamnoaVMxCsPerdr8wvtDQ3fJheXYkS9k5PgPCPxO5LQ0AAyb+MBE ozZfFme3IpXduJ1g0eqb8mvXVbFgVXTRMFDOVHonfcIxGlUBBfXAuv9wDo/kU67gA2KO boO3PdVzx6DwZ+2cLqSk5D7cMwX4yZFPFLsfI8pZ9HP1/BLC/RdOH/sCoEEj1tCHSkhq NVQKyeZ0vg0N5oG+5Eyp31I5dM1Rr2y3eKnLr2zr6ye/77Hba/v5nyFoC4tG9YUu3ivh h46k04PEUDuYL0cJHMc66cZWzU8+0TmUTGOt/A/F5+SO0REqMWCCJN+W6xuoiGS7CpHg mg8w== X-Gm-Message-State: AOJu0YxujKHzYwMv3z1skSiCVWQ0mKPxRbf+DXMpenpYVYEE4a5k6eZR QOh9wUcjoPE+mJhbG+sNpE3lTxVgq5PZ3wjvSQh+n8dwYZr1X9txr+JRVF+DzgZ/j4uOQbO/dsP ldvEMrY+OZbqn3InHRT65WWsqaeEDC4Th X-Google-Smtp-Source: AGHT+IEdRgPOq/Q4efrJMajsz8MwF6fnf1sTTrHISiu+F5ZhWgztr/GitL4h8CpVgeZbw8p7QS1ynsKJMwzMcjb2fkg= X-Received: by 2002:a05:6122:218c:b0:4eb:eb8:a8ee with SMTP id 71dfb90a1353d-4ee3ec78660mr6823870e0c.6.1718533138821; Sun, 16 Jun 2024 03:18:58 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <0cf69a14-f1b5-4077-9d91-d7b579485eec@scriptfusion.com> In-Reply-To: Date: Sun, 16 Jun 2024 04:18:47 -0600 Message-ID: Subject: Re: [PHP-DEV] Static class To: Bilge Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000463982061aff2daa" From: lnearwaju@gmail.com (Lanre) --000000000000463982061aff2daa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable https://github.com/oplanre/php-src/tree/feature/static-class On Sat, Jun 15, 2024 at 3:17=E2=80=AFPM Lanre wrote: > I proposed this previously and have a working implementation, though it > may need some updates. However, I chose not to pursue it further because = it > was clear it wouldn't pass as many people here are unaware that PHP is a > multi-paradigm language. > > I frequently use static classes because they allow me to have private > methods and constants within the class. With namespaced functions, there'= s > no way to declare functions private to the current scope; any function > declared in that namespace will be public unless I use a separate interna= l > namespace, which is impractical. > > I also disagree with the idea that static classes imply global state. The= y > are primarily used for grouping functions. > > Additionally, there's a general acceptance that we can't autoload > functions in PHP, and nothing is being done to address this issue. Yet, i= t > is considered impractical or a "Code Smell" to do one of the only things > that make sense. > > This is a minor change that breaks nothing and would help many people, ye= t > no one is willing to raise any valid arguments against it. > > On Sat, Jun 15, 2024 at 5:19=E2=80=AFAM Bilge wr= ote: > >> Hi Internals, >> >> I want to introduce the `static` keyword at the class declaration level. >> That is, the following would be valid: `static class Foo {}`. >> >> A "static class" is one that only permits static members >> (methods/properties) and could have similar semantics to a static class >> in C# >> < >> https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classe= s-and-structs/static-classes-and-static-class-members>. >> >> In particular: static classes are implied final and they cannot inherit >> from any other class. These specific semantics are negotiable, but in >> practice I've never seen the need to mix inheritance with pure static >> classes. >> >> A static class can be emulated somewhat with a trait in userland, and I >> have long used such a micro library for this purpose >> < >> https://github.com/ScriptFUSION/StaticClass/blob/master/src/StaticClass.= php>. >> >> This works by forcing the constructor to be private, thus preventing >> instantiation, but it cannot guarantee that the consumer does not create >> any instance methods anyway (just that such methods would be useless as >> they would be inaccessible). Ergo, it would be better to have this as a >> language feature so the compiler can provide the necessary guarantees >> and warnings against improper use. >> >> I am not too familiar with internals, but I figure I can probably muddle >> my way through an implementation by following the readonly PR >> , which I imagine has >> similar touch points. The main thing I'd like to ascertain at this stage >> is whether such a PR would have support? >> >> Kind regards, >> Bilge >> > --000000000000463982061aff2daa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sat, Jun 15, 2024 at 3:17=E2=80=AFPM Lanre <lnearwaju@gmail.com> wrote:
I proposed this p= reviously and have a working implementation, though it may need some update= s. However, I chose not to pursue it further because it was clear it wouldn= 't pass as many people here are unaware that PHP is a multi-paradigm la= nguage.

I frequently use static classes because they allow me to hav= e private methods and constants within the class. With namespaced functions= , there's no way to declare functions private to the current scope; any= function declared in that namespace will be public unless I use a separate= internal namespace, which is impractical.

I also disagree with the = idea that static classes imply global state. They are primarily used for gr= ouping functions.

Additionally, there's a general acceptance tha= t we can't autoload functions in PHP, and nothing is being done to addr= ess this issue. Yet, it is considered impractical or a "Code Smell&quo= t; to do one of the only things that make sense.

This is a minor cha= nge that breaks nothing and would help many people, yet no one is willing t= o raise any valid arguments against it.

On Sat, Jun 15, 2024 at 5:19=E2= =80=AFAM Bilge <bilge@scriptfusion.com> wrote:
Hi Internals,

I want to introduce the `static` keyword at the class declaration level. That is, the following would be valid: `static class Foo {}`.

A "static class" is one that only permits static members
(methods/properties) and could have similar semantics to a static class in C#
<https://learn.microsoft.com/en-us/dotnet/cshar= p/programming-guide/classes-and-structs/static-classes-and-static-class-mem= bers>.
In particular: static classes are implied final and they cannot inherit from any other class. These specific semantics are negotiable, but in
practice I've never seen the need to mix inheritance with pure static <= br> classes.

A static class can be emulated somewhat with a trait in userland, and I have long used such a micro library for this purpose
<https://github.com/Sc= riptFUSION/StaticClass/blob/master/src/StaticClass.php>.
This works by forcing the constructor to be private, thus preventing
instantiation, but it cannot guarantee that the consumer does not create any instance methods anyway (just that such methods would be useless as they would be inaccessible). Ergo, it would be better to have this as a language feature so the compiler can provide the necessary guarantees
and warnings against improper use.

I am not too familiar with internals, but I figure I can probably muddle my way through an implementation by following the readonly PR
<https://github.com/php/php-src/pull/7305/files= >, which I imagine has
similar touch points. The main thing I'd like to ascertain at this stag= e
is whether such a PR would have support?

Kind regards,
Bilge
--000000000000463982061aff2daa--