Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127870 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 328F81A00BC for ; Thu, 3 Jul 2025 21:39:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1751578648; bh=mCekIINnlpkqDH1Sre4Pjv/mYhcmm79BhKY+SKapzZ4=; h=Date:From:To:In-Reply-To:References:Subject:From; b=OsTnn4BdGdOcQJeV0A32gbbLgah2U8PHIJLKUnpwNISZGnSAcmi+bH8AAQEKSRO/p eSiipzkg/CoUWknwyCvDx/NFqXdvo2ho6MDMDVPHzxm3bVws+3TU36QSMvfX7Hlnn0 0Aa2/3gLorunVrwrNtzwKDqC8Qr7Y8yin8kDY3/xHFYqO0WgA6C71qq8ytnNDIZyi8 Bx7EDozpDf5CaczgkJJj/tAisBR2Y/pZliBLmqWojhDYGt8zbMfk9UA6NA6AKUpk4Y tS+/l4TWUOcXrRJNms+IalyHsaBj2jqeqJk9XXPDm+KUXXO3+skFsOAeF7EEsDXRMV F5T/VpLrME9Iw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A6AB61801C7 for ; Thu, 3 Jul 2025 21:37:27 +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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE 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 ; Thu, 3 Jul 2025 21:37:27 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfout.phl.internal (Postfix) with ESMTP id 21F6DEC1A4F for ; Thu, 3 Jul 2025 17:39:19 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Thu, 03 Jul 2025 17:39:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=fm2; t=1751578759; x=1751665159; bh=qZeyJoC2kn3gfweg0zHdf DhHQV4RIFKj2GzQxWQbISk=; b=t5k0hQVmO08IrvdcAzS2Ju1U9PlA7wHoiCqAV 2i0gq9JMqAtDsgKz2Z36g7b4vXhDp6kFLb9TUNdOrSAqbY2kc6ueLhh1YgXgSKoC rkJ4djxNp9Kg10+Hvtf1h04920/+Yp9gUaBWrdH7AmQEBYAWUVm2CIN2Ek/BbNnI ysNb+kiPNWx97AcZvE15+5YCqjxSqBzkF1dIX7EKg+sJwduxot7u/eequ7YUbS77 8Bw/6meQFtPN3aVhqKt7b/cWiEI8/mbiy6lkU5pyL65viQei/zDGlij+hooQ4802 bY5GCis17DB1zFY9v6gImArKE8MoRLa4aK+Vdix76+sibLuyw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=fm2; t=1751578759; x=1751665159; bh=q ZeyJoC2kn3gfweg0zHdfDhHQV4RIFKj2GzQxWQbISk=; b=ZWPJ0zZ8GtqbKF5Ql frB+Nr2UKw9OrFY/Er2UDclS6zT6PAD3VLmqX/9pHPy6kMbPnldImIyw0nJbK81z j/1TWjAAqVBCoOHcEc81KdRTdNrVSv8YuPZg2y1qn8QOqnuc5Em3HnRpl/gMWS4C vW+XZVrbJ4wXbOGpf1u8Bag7Hac5dJC6jZvp5Yich4XabyA1hIDD3HhdXmXTVbQv PEVkQM1IEF6AiT5bG93MDHsdbaUowxJQ75creAZqa/wKcNmYyLc7hrJYK0duViyb ds2UdYWab/m97SsQRW/6tcn/08Mjh2q57xah99oID0EZ2KnQv/VR1ZjT95d6Genu s2yQw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddvudefjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvkfgjfhfutgfgsehtjeertdertddtnecuhfhrohhmpedfnfgrrhhrhicu ifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqne cuggftrfgrthhtvghrnhepudegvdelgfeugeehfeejteffudevleethfefgeejffffleeg tddtveekgeekudfgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmpdhnsggprhgtphht thhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhsse hlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 92690700065; Thu, 3 Jul 2025 17:39:18 -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: T13a9b6ebd1dfd435 Date: Thu, 03 Jul 2025 16:38:58 -0500 To: "php internals" Message-ID: <418c05ec-0195-4185-8a35-389bb43edbda@app.fastmail.com> In-Reply-To: References: <1cfc477a-781f-40e9-9e37-dd748ef261be@app.fastmail.com> <20DACB49-3C84-4B23-98E2-35050D9EDAC9@koalephant.com> Subject: Re: [PHP-DEV] [RFC idea] Target-aware attributes Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Thu, Jul 3, 2025, at 12:54 PM, Andreas Hennings wrote: >> > A setter method injection is what I did in AttributeUtils, because it was the only real option. Alternatively, I suppose core could use property setter injection (either a magically named property like $__reflector, or a property that itself has an attribute on it, etc.). That would allow it to be set before the constructor is called, and with property hooks would allow processing either immediately or later in the constructor. The downside here is that Attribute are, generally, serializable, but a Reflection object is not. So if someone wanted a serializable attribute they would have to accept the property, use it, and then remember to unset it at some point. That's clumsy. >> > >> > --Larry Garfield >> > >> >> As someone that's written yet another userland "solution" for this problem, I have an alternative solution, based somewhat on an internalised concept of "never store Reflectors". >> >> Introduce an interface "ReflectorAttribute" (bike shedding to come); which accepts a single Reflector argument. >> >> If the attribute implements the interface, the method is called immediately following instantiation. > > Yep, this is the "method injection" mentioned by Larry, or what I > referred to as "setter injection". > I have not seen your library, but I assume that's where it is going. Yes, that is what AttributeUtils does today, almost exactly. From the docs: #[\Attribute] class AttribWithName implements FromReflectionClass { public readonly string $name; public function __construct(?string $name = null) { if ($name) { $this->name = $name; } } public function fromReflection(\ReflectionClass $subject): void { $this->name ??= $subject->getShortName(); } } (There's a different interface for each type of thing an attribute can be put on because the parameter type is different.) --Larry Garfield