Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130769 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 27CAD1A00BC for ; Mon, 4 May 2026 21:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1777929817; bh=kEYJgELeGfS65O65uvk9pW5Hin82GEwAf2quFkriLB0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=V6+tcOVuguYlFL3nxumfzgnYuXQk9hY8NgBCLcuRbcq9rAA6ddrNExQrNE/Coxh18 GUtvuPpJb7zFJUE4b1ZlZWFvF67qnyfnwz5ayXf7agOHtlq7GQjEJ9eDGWB9MGF0nd FTPpHmWaf1C6fIYkmazpedaXYvvNk0wueI+gPIQUu7eR4ruTekEc4uyLqBpPLefe4q OVeRVMcjCeqkDJoiJ2ZcT5CpSAj13Obg7xuQkZKuKm6xVbINIiKO9gIkSczkDSEPcZ SloiQB+Ah6+AjdS970Nu62G1voHodTZ37AWsqhkJo5TUlKRGzKBw7uuLeyx5frhUk5 OCc5jlwOow+tA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 134DA1801D4 for ; Mon, 4 May 2026 21:23:29 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-yx1-f50.google.com (mail-yx1-f50.google.com [74.125.224.50]) (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:23:28 +0000 (UTC) Received: by mail-yx1-f50.google.com with SMTP id 956f58d0204a3-6587cee8b57so4978317d50.2 for ; Mon, 04 May 2026 14:23:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777929803; cv=none; d=google.com; s=arc-20240605; b=O1kGFK5Sj5ly1YPEXt0sL71cCdJLzgjoS38jN6dl5NPdv6/AAi5NlsBuPt4E1x9vXq Tis5nvN2bTsZHcqHUCNLaHiYmx5eFOS0BLvz3RA6MwEvLO/cxmlkSJU2zhYAyNCpTbN7 sZJ5MFLNQQgoyTMZaRhVupa82AuR3fZz7BMUlowdM1q/D1NdwnaUVKRUk2iYjUFXOKxJ CAYSPIYcxA/5uOIfPDm/Y6ASA1T30GQQXiQFNetHMaV8Lv7WADzOYnuW0ntcYIFE9te/ k5e5kwWgUcAdkKeM8PHudqqDhItaMJ4cPelWVZIbMjTfiwy5TNswxAk+9piNh+H7WEt7 saFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=edAAUl9MAsGWTXOZ2qfixIK680vFJXOhWj+/57VCQe0=; fh=DYT97RqsmUAHGDEpS0f7q28AxeObgzHh5lzdzGYZUM4=; b=EJRnMEb+tJ9chULYnuIVl7u/4SjzFZlXhgzJXrM2m/7zaEZZ3TMh8K++DY+6PwpwIy dlfOLHPdddru49EBrzVLryw4BFGZUL3c355dCcRf1mtFjQGWKDZxQpfUuuZWR3HZq27q yyNMmFiWKGBqQR7hRYBnQBEiopX4REtI/1UjX3EJCKLAVfN/2tsMXwGvnV61W0SMMajf w7prryb+FBteNscuKVP0fnPnl0odvVsP+ZmZ9vpAbMhoxZSYU9QO2iJehsu/9iUP0r4s jzYRf6KGBg03Xk1TznIiksCUUN5urFZ+emjl4aKmEStwVN46j/8bxliJ2m4zpuRCQM1w TScA==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777929803; x=1778534603; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=edAAUl9MAsGWTXOZ2qfixIK680vFJXOhWj+/57VCQe0=; b=rw7pkrEj0x/1x/FeP303ZO94DdhsZhRLbU5yW/v4RP08ooGl+5pPNRlyP8aFCFni5a pVxzfObfHfi1CGhYXvAAnj9R1ZwHKkY6wlIH2ZYAF9aeiMX9e2lV51OL8yF67QY6ZUn5 eB94qxm+9iEG00KA2TGkNYH7NR9H7HAy4eOy+2VLsOJ9naD5AfIEWbT68pOOGkb+wMws j63fLtJ/uVFpQ0anmuHiESQxtWd6T6yN4W8YEZV8kZOuzjd4VbXqrngxfvuW5gWTEEIl /yxhhk9Oht7RsIH3AJKLJh0dgvLKHOo42LcB+qTfA0QMflByNJHePg2dZsk2Jadq7P9L ZjIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777929803; x=1778534603; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=edAAUl9MAsGWTXOZ2qfixIK680vFJXOhWj+/57VCQe0=; b=FpjVZLJHtjFj6CC1CjJCMUrM3OuyWMJgcIgCbYUopfdDXEO+g9sKXCZowXMxDXhUdO rEm32aZreNH7E01gv4NR1guaWorXU2z5501zI60vDRF2cYqN9plndnQeN7+iV6g9QnNn Hr+CdWXpRQyPw1PQ66SpR25cVfTVWtHMCccuEQEwph/rgieTygbXoLh0NwdKgOMzpB1N LQVYeFL7OiObro8RKkpcHwsE70Jta1OlWXzKc0F9OmlYRhe+Af6Q9bPL5knKfZB9fxvQ tNECKteRzaeUaIqzIX0V/2lAY3VWEOFfsKD3w9oaASAVGKISQ4g/T3JkWE6vL+QVWL5i YG6w== X-Gm-Message-State: AOJu0Yz2k4iYbcLj6Hp8H76xH/4DgQ77bCSfhV9hHeQf79Ic1X0/EXm6 8JTXODibPLE0sqkhtUmedRtV+/Z24u8o4LqrGx7cTMvbCzd8EpTzUQgiYTPUKKKOdFc7//ozirP f5xuyyNOzpvZ5wkadxAE6KzolJFfytJFSBA99 X-Gm-Gg: AeBDiesZgp4I1+aegezGDtWixg4sVQZWZMwHh9FWquYjvNj1dydzLTfIb4LSiRgRF/L 0VycDUKvs+JsyKn5ppT5x1j9CV15XQJYvsnfuLNmsUeT4zeY4P3d7SXCpWtovQrQyvxtL9N9TNt xeQQgFFvrZ+0PiOgu+dj+Tu04B44oOMsXMFZeKYN6cXmiU3TRbT7NwUQt/QKION6HUT55drMMx1 PllRhqxoNBV23ely/+2d5JQIbNK059/Yito4HJ3rCkiDAIZaTrRqxK+sH2dl7/mX4Zd+IK69reo /2vD/16d855fmk2Euw== X-Received: by 2002:a05:690c:3513:b0:7bd:7c16:1715 with SMTP id 00721157ae682-7bdac4f3176mr5943957b3.14.1777929803025; Mon, 04 May 2026 14:23:23 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 4 May 2026 14:22:48 -0700 X-Gm-Features: AVHnY4IlWWgoi1o9nMaWAqCO5VWk5cPQMcmY9EN1YeuYdkix_acfHBI7d4D6qSw Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Add ReflectionAttribute::getCurrent() To: Derick Rethans Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000005851a20651048a7b" From: daniel.e.scherzer@gmail.com (Daniel Scherzer) --0000000000005851a20651048a7b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, May 4, 2026 at 2:13=E2=80=AFPM Derick Rethans wrot= e: > 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 method= , > >ReflectionAttribute::getCurrent(), to access the current reflection targ= et > >of an attribute. > > > >* RFC: https://wiki.php.net/rfc/reflectionattribute-getcurrent > > > "a new static method, ReflectionAttribute::getCurrent(), that, when calle= d > from an attribute constructor, returns a reflection object corresponding = to > what the attribute was applied to." > > 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 call. > > I believe it's useful to have something like this, but I'm not in favour > of this approach. > > Would it not be possible for this to be a normal (dynamic) method on the > ReflectionAttrbute object? > > cheers > Derick I agree that this is a bit odd, but the problem with just adding a dynamic method on the ReflectionAttribute object is that, in the attribute constructor, there is no access to the ReflectionAttribute instance (unless you want to extract it from the backtrace, which we shouldn't suggest). Internally, the implementation is doing that backtrace processing in a more stable way than userland probably would. 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: ``` class ReflectionAttribute { // Call from the constructor of an attribute to get the original ReflectionAttribute instance public static function getCurrent(): ReflectionAttribute {} // After using getCurrent(), use this to get the reflection target public function getReflectionTarget(): ReflectionAttributeTarget {} } ``` 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* attribute constructors so that we don't need to process backtraces to an arbitrary depth. An alternative would be to provide the reflection target (or the ReflectionAttribute instance) to the attribute constructor as a parameter, but then we need some kind of way for attribute classes to signal that they want to be given that parameter, and then you get into the weeds on how to opt-in (mark the parameter with a different attribute? add an interface, even though constructors are exempt from signature checks?) that would probably make that harder to reason with for end users. -Daniel --0000000000005851a20651048a7b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Mon, May 4, 2026= at 2:13=E2=80=AFPM Derick Rethans <de= rick@php.net> wrote:
On 4 May 2026 21:24:39 BST, Daniel Scherzer <daniel.e.scherzer@gmail.c= om> wrote:
>Hi internals,
>
>I'd like to start the discussion for a new RFC about adding a new m= ethod,
>ReflectionAttribute::getCurrent(), to access the current reflection tar= get
>of an attribute.
>
>* RFC: https://wiki.php.net/rfc/reflectio= nattribute-getcurrent


"a new static method, ReflectionAttribute::getCurrent(), that, when ca= lled from an attribute constructor, returns a reflection object correspondi= ng to what the attribute was applied to."

This sounds like an arbitrary new rule for just this functionality. I don&#= 39;t think we should have special rules for a single static method call.
I believe it's useful to have something like this, but I'm not in f= avour of this approach.

Would it not be possible for this to be a normal (dynamic) method on the Re= flectionAttrbute object?

cheers
Derick

I agree that this is a bit odd, but = the problem with just adding a dynamic method on the ReflectionAttribute ob= ject is that, in the attribute constructor, there is no access to the Refle= ctionAttribute instance (unless you want to extract it from the backtrace, = which we shouldn't suggest). Internally, the implementation is doing th= at backtrace processing in a more stable way than userland probably would.<= /div>

We could adjust the signature, so that there is st= ill a static method to *get* the ReflectionAttribute, but then a normal dyn= amic method call on that object to get the target reflection object:
<= div>
```
class ReflectionAttribute {

=
=C2=A0 =C2=A0 // Call from the constructor of an attribute to ge= t the original ReflectionAttribute instance
=C2=A0 =C2=A0 public = static function getCurrent(): ReflectionAttribute {}

=C2=A0 =C2=A0 // After using getCurrent(), use this to get the reflectio= n target
=C2=A0 =C2=A0 public function getReflectionTarget():=C2= =A0ReflectionAttributeTarget {}
}
```

but either way I think we need some kind of (C-implemented) backtra= ce 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.

An alternative would be to provi= de the reflection target (or the ReflectionAttribute instance) to the attri= bute constructor as a parameter, but then we need some kind of way for attr= ibute classes to signal that they want to be given that parameter, and then= you get into the weeds on how to opt-in (mark the parameter with a differe= nt attribute? add an interface, even though constructors are exempt from si= gnature checks?) that would probably make that harder to reason with for en= d users.

-Daniel=C2=A0
--0000000000005851a20651048a7b--