Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126401 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 61B471A00BC for ; Fri, 14 Feb 2025 09:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739524063; bh=RaLHTSk0WGIhE3LVabvg81HpvHzBmXl5sC4qzblp/VU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=c/GFO2DImfNSU9OxIIXlkWVrvLy5GXC6Rspzq1tfPU0Uex0nD2JTUG4Uk+wRuQJuG KzXwX6FE7uwEm2k+/rJkkTWs46Fz0NVxuBPhT4pIFEFsQCpHoLv8WZUYL0Sbp2kPb2 mJN+1BT3X1hWaMWJQYnPUkDm8qok0/LtbPrx9ni5T/eF5mFnn+f0ZQ8rETCNYNbQPG Twud1gvKZP24o7Bj/0DhU4GVKPxXSMBeN6ewbGGMk0v0iWx+hGq+gtVS27CoDqFptW UTXaRRPEOdB2tgqkw2h1kxHFHHKUFdjpfFzrPLRSvZvAlT2row6CMaiYE10F6Fewu8 SiNmE/k5NeZ+w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7EFAE1801D7 for ; Fri, 14 Feb 2025 09:07:41 +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.9 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 ; Fri, 14 Feb 2025 09:07:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4YvR8s2sMLz1DDgh for ; Fri, 14 Feb 2025 10:10:21 +0100 (CET) Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by smtp.simply.com (Simply.com) with ESMTPSA id 4YvR8r6jZ3z1DHY3 for ; Fri, 14 Feb 2025 10:10:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=givoni.dk; s=unoeuro; t=1739524221; bh=RaLHTSk0WGIhE3LVabvg81HpvHzBmXl5sC4qzblp/VU=; h=References:In-Reply-To:From:Date:Subject:To:Cc; b=Hoq/kVCqxSPNLmtosqFcVgR2BmPVPiAy9WgIxq4B2aLfUT78Bev9A++1Ta48W74QF kEJ8LzTB1eZxICaBVCsvmBm5a66TGgkv5FSVh94lXpdj2mWnV/MxWw5ymfFzSSfkMP l1piSTB/kkQb9BHgV+y50eHWLwHjqHoXDbtB7gxo= Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2fc1c80cdc8so2147458a91.2 for ; Fri, 14 Feb 2025 01:10:20 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUH37nBQzkqNbGPHwVyKdN4lC+VcfyUhrHpu+1pzsJL+C1lIKvYylJ7rR1ZcBu20iQ9k7BcxmTpiUs=@lists.php.net X-Gm-Message-State: AOJu0Yyd1+QyFtRhDyRs4a+e96B3WjhCrjrXrG6WqjftDx0osQhXNANq OtlhUWtAaXzlG3EQ8203Y6bhIuwpr7OdZXCOihn2MJLwSWmdPqbtwgxYauwRe/eWPcNaXKsf8Vw nTrI8+GQth0dCWOz5Ris4FCJzDRE= X-Google-Smtp-Source: AGHT+IGRY08bGD4uyHA1iZJmPSNiI5Yq1cPGEv2/q+064hnwl4W0BhtjpRCOUlPMqEpV/8bqZCafMcFns8NCEPcPkFs= X-Received: by 2002:a17:90b:5242:b0:2f2:a664:df19 with SMTP id 98e67ed59e1d1-2fbf5bb8dd8mr16061214a91.7.1739524219110; Fri, 14 Feb 2025 01:10:19 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <5c142df3-94f8-45ba-b5c6-af3b4f7caa8b@varteg.nz> In-Reply-To: Date: Fri, 14 Feb 2025 10:10:04 +0100 X-Gmail-Original-Message-ID: X-Gm-Features: AWEUYZnZI-X-ytv760HPV3PtdT0_BQ-M4NwmHQA5V4S9Vo3g4DVMOfpc10Pkwu8 Message-ID: Subject: Re: [PHP-DEV] Re: RFC: Marking return values as important (#[\NoDiscard]) To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: volker@tideways-gmbh.com, internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000289ee8062e168b3b" From: jakob@givoni.dk (Jakob Givoni) --000000000000289ee8062e168b3b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 13, 2025 at 3:17=E2=80=AFPM Tim D=C3=BCsterhus wrote: > Hi > > Am 2025-02-13 09:16, schrieb Jakob Givoni: > > Attributes were added as a structured replacement for docblock props > > and I > > don't like it when they affect how a program actually runs (as long as > > you're not using reflection). > > Excluding the `#[\Attribute]` attribute, PHP currently has 5 native > attributes and they all affect how the program runs. The initial > accepted Attribute RFC even lists several =E2=80=9Cbehavior-affecting=E2= =80=9D > attributes in the =E2=80=9CUse Cases=E2=80=9D section: > https://wiki.php.net/rfc/attributes_v2#use_cases. It is probably fair to > say that use-cases like `#[\NoDiscard]` do not go against the vision > intended by the Attribute RFC. > > You could think of it as the PHP engine using Reflection internally to > do something differently. > I think all the native attributes so far, with the exception of #[\AllowDynamicProperties], only affect the program at compile-time, or by emitting errors. They don't affect the program otherwise by changing behavior, throwing exceptions etc. (As long as you don't use reflection, nor promote errors to exceptions.) AllowDynamicProperties is the only one that may change the program behavior at run-time by throwing an exception if the property is removed from a class while running PHP versions 9.0+. So this is not even a reality yet, since PHP 9 is not yet released. And I think it sets a bad precedent. Perhaps AllowDynamicProperties should have been a language construct instead. Or only fail at compile time. The original attributes RFC does mention "runtime behavior" in the introduction, but none of the use-cases proposed showcase it without using reflection or promoting errors to exceptions (as far as I can see). I don't mean to be rude and use your own words against you, but I found this quote in the "Why an attribute and not a keyword?" section of your #[\Override] RFC: > This RFC proposes an attribute instead of a keyword, because contrary to > other modifiers (e.g. visibility) that are part of the method signature, > the attribute does not affect behavior or compatibility for users that > further extend a given class and neither does it affect users that call t= he > method. It is purely an assistance to the author of a given class. (and I apologize if I misunderstand your intention or take it out of context completely), but I like the sentiment that "the attribute does not affect behavior or compatibility for users" and that it's part of the argument for an attribute instead of a keyword (language construct). I feel like #[NoDiscard] is getting dangerously close to being part of a method signature, especially if it throws exceptions at run-time (which I know it doesn't do in your RFC, so I'm less against it). I might be the only "purist" here, but just thought I would highlight that at least one php developer is hesitant with the direction attributes might be taking :-) Best, Jakob --000000000000289ee8062e168b3b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Thu, Feb 13, 202= 5 at 3:17=E2=80=AFPM Tim D=C3=BCsterhus <tim@bastelstu.be> wrote:
Hi

Am 2025-02-13 09:16, schrieb Jakob Givoni:
> Attributes were added as a structured replacement for docblock props <= br> > and I
> don't like it when they affect how a program actually runs (as lon= g as
> you're not using reflection).

Excluding the `#[\Attribute]` attribute, PHP currently has 5 native
attributes and they all affect how the program runs. The initial
accepted Attribute RFC even lists several =E2=80=9Cbehavior-affecting=E2=80= =9D
attributes in the =E2=80=9CUse Cases=E2=80=9D section:
https://wiki.php.net/rfc/attributes_v2#use_cases= . It is probably fair to
say that use-cases like `#[\NoDiscard]` do not go against the vision
intended by the Attribute RFC.

You could think of it as the PHP engine using Reflection internally to
do something differently.

I think all t= he native attributes so far, with the exception of #[\AllowDynamicPropertie= s],
only affect the program at compile-time, or by emitting error= s.
They don't affect the program otherwise by changing behavi= or,=C2=A0
throwing exceptions etc. (As long as you don't use = reflection, nor promote errors to exceptions.)

All= owDynamicProperties is the only one that may change the program behavior=C2= =A0
at run-time by throwing an exception if the property is remov= ed from a class while running PHP versions 9.0+.
So this is not e= ven a reality yet, since PHP 9 is not yet released.
And I think i= t sets a bad precedent. Perhaps AllowDynamicProperties should have been a= =C2=A0
language construct instead. Or only fail at compile time.<= /div>

The original attributes RFC does mention "run= time behavior" in the introduction,=C2=A0
but none of the us= e-cases proposed showcase it without using reflection or=C2=A0
pr= omoting errors to exceptions (as far as I can see).

I don't mean to be rude and use your own words against you, but I fou= nd this quote in the "Why an attribute and not a keyword?" sectio= n of your=C2=A0#[\Override] RFC:
This RFC proposes an attribute instead of a keyword, because con= trary to other modifiers (e.g. visibility) that are part of the method sign= ature, the attribute does not affect behavior or compatibility for users th= at further extend a given class and neither does it affect users that call = the method. It is purely an assistance to the author of a given class.
=C2=A0(and I apologize if I misunderstand your intention or ta= ke it out of context completely), but=C2=A0
I like the sentiment = that "the attribute does not affect behavior or compatibility for user= s"=C2=A0
and that it's part of the argument for an attri= bute instead of a keyword (language construct).

I = feel like #[NoDiscard] is getting dangerously close to being part of a meth= od signature,=C2=A0
especially if it throws exceptions at run-tim= e (which I know it doesn't do in your RFC, so I'm less against it).=

I might be the only "purist" here,= but just thought I would highlight that at least one php developer=C2=A0
is hesitant with the direction attributes might be taking :-)
=C2=A0
Best,
Jakob
--000000000000289ee8062e168b3b--