Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128240 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 69B1E1A00BC for ; Sat, 26 Jul 2025 14:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753540532; bh=dl/o4Axqs6FAe4GA0+MbkCxyD8cHcTApxB77vqWIyCA=; h=Subject:From:In-Reply-To:Cc:Date:References:To:From; b=IqkvOsymVvqb87eYW8WzOwpzgIthjfm2rSKiAfoPJI/E56Bny35COA74NQAGxUoWD u6GO68tDA6/SZTertBL8/02BIFx6A+aVdOl4PMJXj30ZW4kPvGmxgBljIwn6d76xaW sfapTvtcGnYugMtV09XNuwsbSwQhm8GAtlT/t415fFcjRMEEBdtKWWgkVKLWCWdrJL cZwOUoLXpGp/eaxOWmCa3LlrkyDwO3ozF5+Iys+UJM55ajuysf/QXsGjvXcba2uhJo uFCaQvvR/kSoakihJyPV4/uNTyhIbuTYWRMfsAFvWR9Pr2lt9AMOg4ZoBHJoiXQgQH 20i+wwsq3+N1g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7CE261804F3 for ; Sat, 26 Jul 2025 14:35:31 +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=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,MIME_QP_LONG_LINE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,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 mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 14:35:31 +0000 (UTC) Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-ae0d7b32322so493556466b.2 for ; Sat, 26 Jul 2025 07:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753540634; x=1754145434; darn=lists.php.net; h=to:references:message-id:date:cc:in-reply-to:from:subject :mime-version:content-transfer-encoding:from:to:cc:subject:date :message-id:reply-to; bh=jICIA3vA7GMfLe1l76xorRSQ/XN2WN68V7JmX9YQriQ=; b=jniIuHOFDsTqZIh8gjhB41iz536aJBVJZ83UJz3Ck0pIERd7c77I1h/Fd84bSdXAM6 EgM/oIjRfPBy5WpxzR8VB/3euOn2b7QE7yz5b0iTLH4HJIRi/g+AFPfa57XBLY1KMWzM 1gVBzYgX6R2q65sHUZoRGFnM4LC5eQNhhQ2vH4+Ph7MF9zPYBfFssj9G3z20d+GMoflF RpmeOy06N+jCTr1+6afYcwJqCWKDdlpX1tXCUOKT+ifkO381iaOPLzUB02DXKmBBcnsO yIlvSoltyheyVg0qETjQBo4etRHYOIcFAUUWc9pPnC1jF3vD933l6lEKqGx/Qc2fHhrk +bvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753540634; x=1754145434; h=to:references:message-id:date:cc:in-reply-to:from:subject :mime-version:content-transfer-encoding:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=jICIA3vA7GMfLe1l76xorRSQ/XN2WN68V7JmX9YQriQ=; b=FxMEfUQgJ2dekq9iwVTOtA1JuBZE+1oep2vxHV3Q9rjEAQIPINnsUYm80DKkgHnP8g lyEMiMuDNRDA9C2E51Tg31lJg0HpOD7FzXaao34Bh9qg6xJhGYsC+gGz4AIWEOO2sWs5 UsR+LtloDuMlsUcvsPIciA4wagCRQ2uLgjmK5Yf4lkajoCMDVejzubu8VR6zZiKowYLB zgXiWzfnaRzsoAdMdLzG9kd6aq3VPOk3ldOgrDQ203KEthNP/ypcbEtMjfCtLLygKFcA cj0g0FIHjUUW/fQ9Ix1VjgTJj/M+iWuL34wZOuhxCI2J6EaQJAynnRTJevkxs3ptWSLn yJfA== X-Gm-Message-State: AOJu0YxGZbIvVOJU7aOzONcgMdwhUtVAr5T4jzSw7DMIWFmH3oSIRzlf ZZMuN58UDR6YZ5I+ZCIKArZD6iZxhNbt81ICdQQdpOK1SIsKNxJxiZkqHWzNEQ== X-Gm-Gg: ASbGncs8jN2CaWB+yOW7jjpGOBdIhiBtkI4iYOtDn268FkUVYvhO/VbJOvbniEHpfeC l4T/YDq3qLLbSFRNBbL0CPALI6BaxF6x2ZsGmmNxf1ghiLu0JPKWT8eOZ6YXEtoG7Z0a/COlSlr zb1pDqup4YUFHDEWFpnH9cvMpQxH3s4cIyvX6l8TNcp6hy51rDd8X5484phkwssJ5EKrlNVcWY/ XQZ0rxTmMsImgj1KzA2U2qThgf1BlbzbxWyN/nP2iUVEx8pf5E4586DQFIdehoK7xcfzBJirAEL xf0yYwadFzFp7ySJiZarQBNdYav0ivi1VVbkQhgi5GlPsKsCEYgiXqQL4tUhxpEok48txh8BxZ2 YvLQK5N1PRUYyMsJUg+vW3sdSxF+/CSjJTkZj6V22aaHQ X-Google-Smtp-Source: AGHT+IGJL2msuVnVfi+HUG7a9wQmzU6AqG8ic7eQOiIKz3D1/9zI6MsafFqDLLgxyi758bJvr5KsZQ== X-Received: by 2002:a17:907:608f:b0:ae1:f1e3:ccea with SMTP id a640c23a62f3a-af61740cf30mr752286866b.7.1753540633246; Sat, 26 Jul 2025 07:37:13 -0700 (PDT) Received: from smtpclient.apple ([178.197.194.187]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-af6358a1c32sm150992866b.55.2025.07.26.07.37.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 26 Jul 2025 07:37:12 -0700 (PDT) Content-Type: multipart/alternative; boundary=Apple-Mail-D03900D7-08BE-4C13-BEF8-0848BAA8594E Content-Transfer-Encoding: 7bit Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] Validating #[\Attribute] targets In-Reply-To: Cc: php internals Date: Sat, 26 Jul 2025 16:37:02 +0200 Message-ID: <5CF14046-F7CD-43D1-9A07-A93CDB14EA5D@gmail.com> References: To: Daniel Scherzer X-Mailer: iPhone Mail (22F76) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail-D03900D7-08BE-4C13-BEF8-0848BAA8594E Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > Le 25 juil. 2025 =C3=A0 18:37, Daniel Scherzer a =C3=A9crit : > =EF=BB=BF > Hi internals, >=20 > The #[\Attribute] attribute is used to mark classes as being usable as att= ributes. It currently does not trigger any error if added to a trait, interf= ace, enum, or abstract class. However, if any of those *were* used as an att= ribute, calling ReflectionAttribute::newInstance() would fail; if you are no= t going to call ReflectionAttribute::newInstance(), then you don't really ne= ed to mark the trait/interface/enum/abstract class as an attribute. >=20 > I have proposed https://github.com/php/php-src/pull/19154 to add validatio= n to the #[Attribute] attribute, and it was suggested that I post here on th= e mailing list in case there were any objections. So, are there? >=20 > -Daniel Hi, Validating more precisely the target of #[Atrribute] is reasonable. Now, obs= erving that there are several internal attributes that may benefit this capa= bility (e.g. #[Attribute], #[AllowDynamicProperties], #[Deprecated] on trait= s as currenty voted on), I wonder if we can also expose this capability to u= ser-defined attributes? Concretely, there could be the following additional c= onstants: * Attribute::TARGET_INTERFACE * Attribute::TARGET_ABSTRACT_CLASS * Attribute::TARGET_TRAIT * Attribute::TARGET_ENUM * Attribute::TARGET_REGULAR_CLASS and Attribute::TARGET_CLASS would be equal to the result of combining all of= those with the `|` operator.=20 =E2=80=94Claude=20 =E2=80=94Claude=20 --Apple-Mail-D03900D7-08BE-4C13-BEF8-0848BAA8594E Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


Le 25 ju= il. 2025 =C3=A0 18:37, Daniel Scherzer <daniel.e.scherzer@gmail.com> a= =C3=A9crit :

=EF=BB=BF
Hi internals,

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, enu= m, or abstract class. However, if any of those *were* used as an attribute, c= alling ReflectionAttribute::newInstance() would fail; if you are not going t= o call ReflectionAttribute::newInstance(), then you don't really need to mar= k the trait/interface/enum/abstract class as an attribute.

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

-Daniel

Hi,

=
Validating more precisely the target of #[Atrribute] is reasonable. Now= , observing that there are several internal attributes that may benefit this= capability (e.g. #[Attribute], #[AllowDynamicProperties], #[Deprecated] on t= raits as currenty voted on), I wonder if we can also expose this capability t= o user-defined attributes? Concretely, there could be the following addition= al constants:

* Attribute::TARGET_INTERFACE
* Attribute::TARGET_ABSTRACT_CLASS
* Attribute::TARGET_TRAIT
* Attribute::TARGET_ENUM
* Attribute::TARGET_REGULAR_CLASS=

and Attribute::TARGET_CLASS would be equal to the r= esult of combining all of those with the `|` operator. 

<= /div>
=E2=80=94Claude 

=E2=80=94Claude&nbs= p;


= --Apple-Mail-D03900D7-08BE-4C13-BEF8-0848BAA8594E--