Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128235 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 lists.php.net (Postfix) with ESMTPS id DCF711A00BC for ; Sat, 26 Jul 2025 07:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753516462; bh=SPUUEaTs8S8P9C1koYLhw1R5QuFKQ5d1DBDBy5lJvIk=; h=Date:From:To:In-Reply-To:References:Subject:From; b=RNkTby+4Q+1cFVeHxNdRoWFyPPOxr7F8ZbXVL+Dx/G4UTZ49QOxae5/bxWK4ALa9O BYtpL4/azZpYwZsjZ8F7RZoPSHp/ckpCtO6BFY4ndw2CAqCCbubUFAPAswPwp4LDjJ CrmQsyPR6DD/25doMX/tDd+V/qEFu/tBCEhNDYl63n21BTe3VVYKdIahdDRIFTGFAo Z/hQ1o0FvGk+m3DccUsIhAQ9EuoTvueZSlSBjCRZOCzvjpzsW/6ELtTu0akv0hGZ/9 vcItolctTwBnxzPKtVcyqiciCybKMRPczmZtZ8BkJxhPPX0wI7Z7SZ3fS1tUgCa+cq ZGkYueaVgvntw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4F97118006C for ; Sat, 26 Jul 2025 07:54:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) (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 ; Sat, 26 Jul 2025 07:54:07 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 76B6AEC01FE for ; Sat, 26 Jul 2025 03:55:51 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Sat, 26 Jul 2025 03:55:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1753516551; x=1753602951; bh=SPUUEaTs8S 8P9C1koYLhw1R5QuFKQ5d1DBDBy5lJvIk=; b=B9dRJURV4vZbtzCn4mKBPFqeVw K+3hBDJZLOT1fTxQQuiorQ4OYRep+sZvCWPpsg1rTDrI/Zblkx2L5SaYs0QMCFpE w743K5ZfMrDMy76qN8J052NlRUUtIsB8v/TtS70H4AWlHL03ZERaKAL53NBDlG7v fuprGbvTB/b0r3ylbqB/TDIici1seoi4VaLnr2O+2jwORkdj31GkENYhWT2B/Qv0 jxxWgJtqCOOruCo5wmFFzooNWy17ZwSkh69d2M+hUfHPoeZlwVY+FX5/wpCALzF9 p9XZywp9kyyeJzgoZGGuFB7d6AsN++8QoNSPhKfBTXqsFI1JAI/o1v6C85qA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1753516551; x=1753602951; bh=SPUUEaTs8S8P9C1koYLhw1R5QuFKQ5d1DBD By5lJvIk=; b=ctiIoLnvYGodlFUR8nGoN/5X6+c/aXbNM/MUEYqxME7ZWN7RaAi 0OCLqmf3dLkGn1j02PBXswI1Iic+usW+2OK2XMMYPdYbzaP16FV+FCDLDRn4wjoI 5/oGCEMme5tLxGlx1PbIEybdo2i2LnCR7y5VGf+Z/zfEkbRj3mHETZF5JwNG/Kcf hMEYafD4TrOrEHMPSfg8vV3XM5UG6p2SJU4n5pLVvQ26Ms0yORY7nFe3L7PoHtpL spQp7YR/0QvM69fWdyujqP0E5jPcOm6Q3cEB1Jq661Bm9A82TfISYZHbQZ61HJ8Q QX+Gs5Ytr0D34t0xoXSdXlqwqziE4Xa+1Hg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdekheekjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepofggfffhvffkjghfufgtsegrtderreertd ejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdr tghouggvsheqnecuggftrfgrthhtvghrnhepiedthffhvdffhfettdfgveefgfeugeegud eukeejheeigefghfeiveelfeefueefnecuffhomhgrihhnpehgihhthhhusgdrtghomhen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgsse gsohhtthhlvggurdgtohguvghspdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhp ohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 19F8E1820074; Sat, 26 Jul 2025 03:55:50 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: T52980399d72dd973 Date: Sat, 26 Jul 2025 09:55:30 +0200 To: internals@lists.php.net Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] Validating #[\Attribute] targets Content-Type: multipart/alternative; boundary=94ee00059e8c48438503844c163ac875 From: rob@bottled.codes ("Rob Landers") --94ee00059e8c48438503844c163ac875 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Fri, Jul 25, 2025, at 18:33, Daniel Scherzer wrote: > Hi internals, >=20 > The #[\Attribute] attribute is used to mark classes as being usable as= attributes. It currently does not trigger any error if added to a trait= , interface, enum, or abstract class. However, if any of those *were* us= ed as an attribute, calling ReflectionAttribute::newInstance() would fai= l; if you are not going to call ReflectionAttribute::newInstance(), then= you don't really need to mark the trait/interface/enum/abstract class a= s an attribute. >=20 > I have proposed https://github.com/php/php-src/pull/19154 to add valid= ation to the #[Attribute] attribute, and it was suggested that I post he= re on the mailing list in case there were any objections. So, are there? >=20 > -Daniel Since \Attribute itself is an attribute, I wouldn=E2=80=99t expect it to= be validated until newInstance is called. In fact, if I remember correc= tly from the original discussion, this was done deliberately so it would= be forward compatible. Further, by making it compile-time validated, I = would be misled to think my own attributes would be validated at compile= time (which I think is a better solution than hodgepodging our way ther= e).=20 =E2=80=94 Rob --94ee00059e8c48438503844c163ac875 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Fri, Jul 25, 2025, at 18:33, Daniel Scherzer wrote:=
Hi internals,

The #[\Attribute] attribute is= used to mark classes as being usable as attributes. It currently does n= ot trigger any error if added to a trait, interface, enum, or abstract c= lass. However, if any of those *were* used as an attribute, calling Refl= ectionAttribute::newInstance() would fail; if you are not going to call = ReflectionAttribute::newInstance(), then you don't really need to mark t= he trait/interface/enum/abstract class as an attribute.

I have proposed https://github.com/php/php-src/pull/19154 to add validat= ion to the #[Attribute] attribute, and it was suggested that I post here= on the mailing list in case there were any objections. So, are there?

-Daniel

Since \Attribute itself is an attribute, I wouldn=E2=80=99t expe= ct it to be validated until newInstance is called. In fact, if I remembe= r correctly from the original discussion, this was done deliberately so = it would be forward compatible. Further, by making it compile-time valid= ated, I would be misled to think my own attributes would be validated at= compile time (which I think is a better solution than hodgepodging our = way there). 

=E2=80=94= Rob
--94ee00059e8c48438503844c163ac875--