Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130770 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 3EA011A00BC for ; Mon, 4 May 2026 21:37:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1777930669; bh=oa2CrECctTyEAdSAGliYy2tCIyo+oktH4siM2225bdM=; h=Date:From:Cc:In-Reply-To:References:Subject:From; b=EvUVBoDRZif+0C/No2gKsudcZVM5ZwlYHMk4jW19cs8MN6/uPYvhAu6aSwa+jjxqt LJ5OSWpgehxHGrIJWsGwuO+FqIN8ciL/IQ2Jpxnbkvd4dB0jM5cBB0ajCQPZoSI7wx nx6cFOLRi2eaviJW5//pwk+9Y5kTixWkJt613qWQnJ60UuHigP0kgoRufhBTxvSSbp ur3EBtolFgfjOewqgg6SHpmnSIudzTELg/SJxOF7tlxEHRUybOSMA3bi+V86sbb24R E1T875LSjBsvU84opyDHWSKrvKH4X0zC7LM8khYDXB4jScmObWa/hHVNabYgqNPuFA Pjylf//WBBztw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8D8D1180040 for ; Mon, 4 May 2026 21:37:45 +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.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, MISSING_HEADERS,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (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 ; Mon, 4 May 2026 21:37:45 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.stl.internal (Postfix) with ESMTP id E6B877A0084 for ; Mon, 4 May 2026 17:37:38 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-12.internal (MEProxy); Mon, 04 May 2026 17:37:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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; s=fm1; t=1777930658; x=1778017058; bh=WqzCcWO9wX//XBThjqbMw0JsX+V1XhQJZriDwjeD3Ko=; b=k9L2z0OWP87q waeh4DU48iaPo7TzrC0Tr8nBYFT69oIM64ZaOtkRY7r43OCCAxYGYBwC7suoyokO Auyd7+CySKHII9zn38XI83QgZGaGRPzJk8KBDqIiklBZP3XkKlMHsnVCR9uN73Xo xT+FFYylQhdm2EfmPHCbpqTlUBZjQPXZoc0E07cX3a008sV5Sy/Bwnro982Yhjxy XZu32HiuR6PpksBvb1ridbvZpICkrkZvUR9blNvo3UNQBpanolzsLKJkXuTaOjuF SlWucYbUyfUrWxqg0p4/OBi4kES+pm/zj/LZ5ow51JEEdCJvzhABFSR26UXIqWTD maYXLUd9Ng== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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 :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1777930658; x=1778017058; bh=WqzCcWO9wX//XBThjqbMw0JsX+V1XhQJZri DwjeD3Ko=; b=q9ntDbLkCMdO5kxScqMUWydbCFTYwLJytk8L8crjcMo/5n3wEQY xGIn0GLtI/C+CJAZ4IieD5Xr6fE7408PFzDdHCkN4pvepcR9nKiQuyoBrSYdIyeQ W52iEFjlyYo7CM5YH69uI8IDZ8UbAi+5MzdyhzkpWSuDsSLqYLXbTrj+yaxx7OKe mD9qbAJA5IcLd4gyph0P6MXIKhoNVlTcAbs5lYOVpr604S2l0Y1bxVXnO0VjDO95 QVGWcIjRz3IEG3aSp26mio78HowWmQvRlIx46RqCk5ZlchCLTIO97uHP9kB71FRK j6RBrRRU5o2p7A5Lqiklwg5Ib6LP4OLYkig== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdelleelgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecumhhishhsihhnghcuvffquchfihgvlhguucdlfedtmdenuc fjughrpefoggffhfevkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfn rghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtth gvrhhnpefgffeuueeujedvgeeigefhtdeitddufeeuhfettdevheejieefjeegkedtgfev gfenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggp rhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnh grlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 0FE49182007A; Mon, 4 May 2026 17:37:38 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AXeyPji2E7Fw Date: Mon, 04 May 2026 23:37:16 +0200 Cc: internals@lists.php.net Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] [Discussion] Add ReflectionAttribute::getCurrent() Content-Type: multipart/alternative; boundary=fd7a9cd544159590dc7f575470aeddfd19d10238 From: rob@bottled.codes ("Rob Landers") --fd7a9cd544159590dc7f575470aeddfd19d10238 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, May 4, 2026, at 23:22, Daniel Scherzer wrote: >=20 > On Mon, May 4, 2026 at 2:13=E2=80=AFPM Derick Rethans = wrote: >> On 4 May 2026 21:24:39 BST, Daniel Scherzer wrote: >> >Hi internals, >> > >> >I'd like to start the discussion for a new RFC about adding a new me= thod, >> >ReflectionAttribute::getCurrent(), to access the current reflection = target >> >of an attribute. >> > >> >* RFC: https://wiki.php.net/rfc/reflectionattribute-getcurrent >>=20 >>=20 >> "a new static method, ReflectionAttribute::getCurrent(), that, when c= alled from an attribute constructor, returns a reflection object corresp= onding to what the attribute was applied to." >>=20 >> This sounds like an arbitrary new rule for just this functionality. I= don't think we should have special rules for a single static method cal= l. >>=20 >> I believe it's useful to have something like this, but I'm not in fav= our of this approach. >>=20 >> Would it not be possible for this to be a normal (dynamic) method on = the ReflectionAttrbute object? >>=20 >> cheers >> Derick >=20 > I agree that this is a bit odd, but the problem with just adding a dyn= amic method on the ReflectionAttribute object is that, in the attribute = constructor, there is no access to the ReflectionAttribute instance (unl= ess you want to extract it from the backtrace, which we shouldn't sugges= t). Internally, the implementation is doing that backtrace processing in= a more stable way than userland probably would. >=20 > We could adjust the signature, so that there is still a static method = to *get* the ReflectionAttribute, but then a normal dynamic method call = on that object to get the target reflection object: >=20 > ``` > class ReflectionAttribute { >=20 > // Call from the constructor of an attribute to get the original R= eflectionAttribute instance > public static function getCurrent(): ReflectionAttribute {} >=20 > // After using getCurrent(), use this to get the reflection target > public function getReflectionTarget(): ReflectionAttributeTarget {} > } > ``` >=20 > but either way I think we need some kind of (C-implemented) backtrace = processing, and because of that it makes sense to limit this to *just* a= ttribute constructors so that we don't need to process backtraces to an = arbitrary depth. >=20 > An alternative would be to provide the reflection target (or the Refle= ctionAttribute instance) to the attribute constructor as a parameter, bu= t then we need some kind of way for attribute classes to signal that the= y want to be given that parameter, and then you get into the weeds on ho= w to opt-in (mark the parameter with a different attribute? add an inter= face, even though constructors are exempt from signature checks?) that w= ould probably make that harder to reason with for end users. >=20 > -Daniel=20 What about simply allowing an acceptance of the ReflectionAttribute in t= he constructor? Engine-level injection, basically. You could have it tra= nsparent from the attribute (kinda like self from python): #[Attribute] class Att { public function __construct(RelectionAttributeTarget $self, string $na= me) {} } function thing(#[Att("name")] string $b) {} It'd still be something "special" but attributes are already kinda speci= al and magical. =E2=80=94 Rob --fd7a9cd544159590dc7f575470aeddfd19d10238 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Mon, May 4, 2026, at 23:22, Daniel Scherzer wrote:<= /div>

<= div>

    // After using getCurrent(), use this to= get the reflection target
    public function getRe= flectionTarget(): ReflectionAttributeTarget {}
}
```

but either way I think we need some kind = of (C-implemented) backtrace processing, and because of that it makes se= nse to limit this to *just* attribute constructors so that we don't need= to process backtraces to an arbitrary depth.

A= n alternative would be to provide the reflection target (or the Reflecti= onAttribute instance) to the attribute constructor as a parameter, but t= hen we need some kind of way for attribute classes to signal that they w= ant to be given that parameter, and then you get into the weeds on how t= o opt-in (mark the parameter with a different attribute? add an interfac= e, even though constructors are exempt from signature checks?) that woul= d probably make that harder to reason with for end users.

=
-Daniel 

What about simply allowing an acceptance of the ReflectionAttribute i= n the constructor? Engine-level injection, basically. You could have it = transparent from the attribute (kinda like self from python):
=
#[Attribute]=
=0Aclass Att {=0A  public function __construct(RelectionAttributeTarget =
$self, string $name) {}=0A}

function thing(#[Att("name")] string $b) {}

It'd still be something "special" but attributes = are already kinda special and magical.

=E2=80=94 Rob
--fd7a9cd544159590dc7f575470aeddfd19d10238--