Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123801 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 3FACB1A009C for ; Tue, 25 Jun 2024 02:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719282209; bh=O18264/03gyBmoCN4jGZ47LiZDVpXXI+9B/gCN1pmHE=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=RvLc3d9mHS50p+TnE9DxEOFqSxDkLJ6TdRCQd9wJn8QTKUHF6wMbQeJ3Sqwuxa2VB UG+A4JmxFuszpkNYkx8bK6HK2Q7f2CydmKuFV163GpRFH/5JblNXENjwsWD6KAGzej Iik2rhEOPpIMPHIYtKsDSsFwu+u7AbbqziwE/QNQOGXEMHKGJg6wDLVDv2wdhMfwqR Q+rcdgzepzQwKkr7wrhsPTyYPk+V3WJLB8sKsVxy41IK1xUbIuV4hUQRJAbcloqJm1 NmgOtx2yro5xlE9coi767n7W2IMAgUj9HcDYx21jwZDSD5zJMjrEFSpNsNYkibSyT5 zBlAmA6p09uhw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 88248180083 for ; Tue, 25 Jun 2024 02:23:28 +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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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 ; Tue, 25 Jun 2024 02:23:27 +0000 (UTC) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-643efaf0786so18201747b3.1 for ; Mon, 24 Jun 2024 19:22:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1719282130; x=1719886930; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=7LAXqm2nXo6MdCA8ZDBdySdgMZuxLrE/XWARpht/4Ww=; b=q5/y9kHCQnGAmottralxdQRugQNV+I9VSGxNY2Lzet4Z0VNzBZ98Zpuxt7Ry8MlJZC CXmnobL4hMrJtHGmsl3c4BpeYINtv7uh9oUIQP8mayx2Kuwsvw1fx5dMQs5rUlXlo4pg B4Em6O5YfKeg3TIuYMVlNQhO+JcscCCFXbK45FVOEswPCFkLXuxDL9uYhkarkKa5MpUs R92w49MYsxOz/ASt/pg2XLnf9HtU3glgbwaG3lmGQYmJHHj/8p1LW4/7MFhpRal8FK40 qmZ8LgRqRFD8KrNafPv4DcbEWv8c5RKQKJWN5aD0F/AXv3mSAXk3uAgNh3x3gVPfK5GV vEng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719282130; x=1719886930; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7LAXqm2nXo6MdCA8ZDBdySdgMZuxLrE/XWARpht/4Ww=; b=UZZiFwDAkTVEKj5zrpQEeV4uUAeYNSSCtp7HZ12UQ/s7eQMUY+CpTci7yDGM4zkzf6 OPqnSfitY8+0lC5dqO6mC0oZekzKREdDCZ7AqJ2DyCWXkDCAYUJc2bNZnD2yaIweTi5R pI8b/s97Wb7HtoNZclIxEhw87WF+B7J16IEeY9OrtsCyh25uLKqfJm0CalfCHzTX6/et xogFTtFY3HShayNlRSw+25dEJK6X65XKsdflsOeqNkBKiaXIYMDMsPHUTjpbgutyLBhY aymKeIhF4hRccu98oQ0K2jhe2MipeDglab0GQNbB9oBJcFY3MA05JRkYsTG8EeF9r781 l6UQ== X-Forwarded-Encrypted: i=1; AJvYcCWQr0wGbi1hRvV08eM2c/BrvfAlJYX+JFx+JcoPhQfy+q3Rg13OO+KPR+xv1CWPhoRuD2eyemL44TS9LtJXuoZ5FGr+BdMZ1A== X-Gm-Message-State: AOJu0Ywn39QHEQOLqB0QhSdNHxBBm0ZE2Uj5/TpfTS983zs7NRJ2fOj1 pZiH+dNjbcDC122D4Ttj1L1wB8zy6lC1UdAia46Bv9GLlalVJvq0grWU1Uy7tY8= X-Google-Smtp-Source: AGHT+IHnrB7NC9DMkZxZCm5nOWA7qlwiBCeZUwrF7VdGkwckW8YTFUFKgw1FezGs+4ldT3mI79rwPg== X-Received: by 2002:a05:690c:3747:b0:62c:dcb2:a75b with SMTP id 00721157ae682-64342d9ab69mr49596327b3.38.1719282130166; Mon, 24 Jun 2024 19:22:10 -0700 (PDT) Received: from smtpclient.apple (c-98-252-216-111.hsd1.ga.comcast.net. [98.252.216.111]) by smtp.gmail.com with ESMTPSA id 00721157ae682-63f11b0f8c0sm33273987b3.45.2024.06.24.19.22.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jun 2024 19:22:08 -0700 (PDT) Message-ID: <882BD9E0-42E9-4C84-A144-7C1DFC4CE5EB@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_14FBFB21-A0E3-4382-9D59-EB4444809A89" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: [PHP-DEV] [RFC] Static class Date: Mon, 24 Jun 2024 22:22:07 -0400 In-Reply-To: <88D83E92-94BE-4548-B398-8F5C74765FFD@gmail.com> Cc: Bilge , php internals To: Claude Pache , ayesh@php.watch References: <88D83E92-94BE-4548-B398-8F5C74765FFD@gmail.com> X-Mailer: Apple Mail (2.3696.120.41.1.8) From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_14FBFB21-A0E3-4382-9D59-EB4444809A89 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Jun 24, 2024, at 3:53 AM, Ayesh Karunaratne = wrote: > - Why is it a class-level flag and not an attribute (similar to the > `#[Override]` attribute in PHP 8.3) ? =46rom my perspective that would create much confusion among every PHP = developer who has not committed to memory when to use `static` as a = class keyword and when to use it as an attribute. Given the concept already exists in keywords I would strongly argue that = it makes no sense to introduce as an attributes in core PHP. =20 Attributes are great for concepts new to PHP, IMO, but not for existing = concepts already part of PHP implemented with keywords. > On Jun 24, 2024, at 4:27 AM, Claude Pache = wrote: > * The main purpose of the `abstract` keyword is to prevent a class to = be instantiated, which (in case of static class) is more semantically = described by the `static` marker. Beyond that, it just allows to declare = a method that, if implemented by a subclass, should have a compatible = signature. Most notably, it does not prevent the other static members of = the class to be used directly. Given a primary purpose for being able to declare a class `static` is to = signal intent, disallowing `abstract static` classes seems at odds with = that goal. Of course it is currently true that `static` methods of `abstract` = classes can be called from outside a class and its class hierarchy, so = if we allow declaring `abstract static` classes then it would never in = the future be possible to lock down calls of `static` methods to those = `abstract` classes. So IMO it would be better to disallow calling `static` methods from = outside a declared `abstract static` class and its inheritance hierarchy = as part of this RFC. That would be backward compatible since there are = currently no classes that are declared in that manner. Doing otherwise = would force those who want to declare a class as both `static` and = `abstract` to have to make a choice rather than being able to signal = their full intent. Which brings us back to the "implied" vs. "explicitly = declared" bifurcation I mentioned in a prior email. BTW, I am assuming it is technically possible to disallow calling = methods for classes declared both `abstract` and `static` without = considerable difficulty in implementation and without creating a = significant drain on performance.=20 -Mike=20 P.S. I would argue the same for `readonly static` properties, but as = that seems those would require an involved discussion about the exact = rules to implement I am demurring on that topic.= --Apple-Mail=_14FBFB21-A0E3-4382-9D59-EB4444809A89 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
On Jun = 24, 2024, at 3:53 AM, Ayesh Karunaratne <ayesh@php.watch> = wrote:
- Why is it a class-level flag and not an = attribute (similar to the
`#[Override]` attribute in PHP = 8.3) ?

=46rom my perspective that would create much confusion among = every PHP developer who has not committed to memory when to use `static` = as a class keyword and when to use it as an attribute.

Given the concept = already exists in keywords I would strongly argue that it makes no sense = to introduce as an attributes in core PHP.  
Attributes are great for concepts new = to PHP, IMO, but not for existing concepts already part of PHP = implemented with keywords.

On Jun 24, 2024, at 4:27 AM, Claude Pache = <claude.pache@gmail.com> wrote:
* The main purpose of the `abstract` keyword is to prevent a = class to be instantiated, which (in case of static class) is more = semantically described by the `static` marker. Beyond that, it just = allows to declare a method that, if implemented by a subclass, should = have a compatible signature. Most notably, it does not prevent the other = static members of the class to be used directly.

Given a primary purpose for = being able to declare a class `static` is to signal = intent, disallowing `abstract static` classes seems at odds = with that goal.

Of course it is = currently true that `static` methods of `abstract` classes can be called from outside a  class and its class = hierarchy, so if we allow declaring `abstract static` classes then it = would never in the future be possible to lock down calls of `static` = methods to those `abstract` classes.

So IMO it would be better to disallow = calling `static` methods from outside a declared `abstract static` class = and its inheritance hierarchy as part of this RFC. That would be = backward compatible since there are currently no classes that are = declared in that manner.  Doing otherwise would force those who = want to declare a class as both `static` and `abstract` to have to make = a choice rather than being able to signal their full intent. Which = brings us back to the "implied" vs. "explicitly declared" bifurcation I mentioned in a prior = email.

BTW, I am assuming it is = technically possible to disallow calling methods for classes declared = both `abstract` and `static` without considerable difficulty in = implementation and without creating a significant drain on = performance. 

-Mike 

P.S. I would argue the same for `readonly = static` properties, but as that seems those would require an involved = discussion about the exact rules to implement I am demurring on that = topic.
= --Apple-Mail=_14FBFB21-A0E3-4382-9D59-EB4444809A89--