Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121718 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 59563 invoked from network); 19 Nov 2023 23:03:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Nov 2023 23:03:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AA9C518002B for ; Sun, 19 Nov 2023 15:03:23 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,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 autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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, 19 Nov 2023 15:03:23 -0800 (PST) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-40838915cecso11585355e9.2 for ; Sun, 19 Nov 2023 15:03:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700434999; x=1701039799; darn=lists.php.net; h=mime-version:subject:references:in-reply-to:message-id:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=fFDVgWI4cmOzG+UwBwRzMuwtK7SeTse0X7j8zS4MVG4=; b=jpFADvxUqBHb4drO40ExeE/IOCXXdEaCXZmRlaGiRKWZHZwBqsL1KLSDbGVj3hOZs/ 9fJutfENvSJGDcyv+HimA6r6WU2ZE41+Q2F2wvdS3164dhxrAv6M5qJIyLR9c4rJi3G4 UJSLI+Gm6leJaS41EBq+pZtOu2w/SrKwyx3NqeRKD4fRSQT7LZ/DEnHlDvcW3sgX7G37 8CQFmL2SdcX6WtcjzVhiQkg0dvhGzmgye/i0IE2enn3L7Kx5BKdZ91S5ym+wUgB63Ohz Tz3lHzz3hC1LkJJiaO/SEljZ6FVttkvW0qdllWQD4MgR58NrY/Aaz7IsPyVHXzkyWGA6 PGpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700434999; x=1701039799; h=mime-version:subject:references:in-reply-to:message-id:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fFDVgWI4cmOzG+UwBwRzMuwtK7SeTse0X7j8zS4MVG4=; b=mfslLaypnhWFl2us1rLQZlIkYhjJnC9EDJOFVnH+EEMbAvn5EU4rgWbLwmJrskaJ+C WmkQKRXXPX1WHnMu4uJUSpwhM4mqlLEJ9hMh3SwR0NjMJx9YnZECZVXJIWYqHfFebDB3 6KJJ+1OyZjAR2du4HJKb0Mpy8PYK5s5uD7RJlTnEtOVfAyGdWYyiIvwTTIZgmq0TsQk6 nt7krCIzi9L4HPwf4a9T/EiozStGK5b9S6Ga67oC9ofwySzxjH/90l+4CjSaaLBchsvw yeZ8XbwQg0CZF4QrgARW0tzByLqGKJwqRzwZwA5UHNky77m80mQ/ZnFJT2KOE2MiNUkq 2tyw== X-Gm-Message-State: AOJu0Ywu1OFPL8IeVaqww+EgAo9WTKuji/l1Unq2yWOx9eTAXbV0UeKc RL3GuPpGXwg03M+Uazbh2jltkCRBQ08= X-Google-Smtp-Source: AGHT+IFEPza6MyJLmMOOwMVIOcoTtttR8mfL+ajyzBcFVE8McnV3xfgViG21dgmMgGnl1T0guWdwKA== X-Received: by 2002:a05:600c:548c:b0:408:364e:34a2 with SMTP id iv12-20020a05600c548c00b00408364e34a2mr5353482wmb.10.1700434998751; Sun, 19 Nov 2023 15:03:18 -0800 (PST) Received: from [127.0.0.1] (as198747.daniil.it. [128.116.205.77]) by smtp.gmail.com with ESMTPSA id x7-20020a1c7c07000000b0040684abb623sm15412801wmc.24.2023.11.19.15.03.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 Nov 2023 15:03:18 -0800 (PST) Date: Mon, 20 Nov 2023 00:03:18 +0100 (GMT+01:00) To: internals@lists.php.net Message-ID: <1546bedc-8306-48e8-b2e3-af1e6069a661@gmail.com> In-Reply-To: <79d675e3-95b4-40bb-baf4-3e1c998f5390@online-presence.ca> References: <79d675e3-95b4-40bb-baf4-3e1c998f5390@online-presence.ca> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_4_78162761.1700434998241" X-Correlation-ID: <1546bedc-8306-48e8-b2e3-af1e6069a661@gmail.com> Subject: Re: [PHP-DEV] RFC Proposal - static modifier for classes From: daniil.gentili@gmail.com (Daniil Gentili) ------=_Part_4_78162761.1700434998241 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 19 nov 2023 22:28:16 Lanre Waju : > Hi, similar to the abstract and readonly modifiers to classes (similar in= syntax only), I propose a class level "static" modifier that ensures: >=20 > 1. The class cannot be instantiated and will throw an exception if attemp= ted. >=20 > 2. All methods and variables in the class are implicitly static. >=20 > 3. (optional based on community input) It should have the same effect on = traits and interfaces >=20 > For example: >=20 > static class X { >=20 > =C2=A0=C2=A0=C2=A0 const int k =3D 1; >=20 > =C2=A0=C2=A0=C2=A0 private string $a >=20 > =C2=A0=C2=A0=C2=A0 function foo():void{} >=20 > =C2=A0=C2=A0=C2=A0 private function bar():void{} >=20 > } >=20 > would be equivalent to >=20 > class X { >=20 > =C2=A0=C2=A0=C2=A0 const int k =3D 1; >=20 > =C2=A0=C2=A0=C2=A0 private static string $a >=20 > =C2=A0=C2=A0=C2=A0 public static function foo():void{} >=20 > =C2=A0=C2=A0=C2=A0 private static function bar():void{} >=20 > } >=20 > and so on. I will be implementing this myself it it gets approved. >=20 > Cheers, >=20 > Lanre >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php Hi, Super on board with this, I felt the need for this feature uncountable time= s in many years, usually the temporary solution was just to mark the class = as final and create a private constructor, but especially the private const= ructor part makes it a bit ugly, too indirect and not immediately obvious. The only doubts I have about this proposal are the omission of static keywo= rds for functions and properties. I understand this is inline with readonly classes, but I don't feel like st= atic is a keyword that should be omittable when declaring static methods an= d properties. Regards, Daniil Gentili. ------=_Part_4_78162761.1700434998241--