Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127734 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 234C01A00BC for ; Sun, 22 Jun 2025 20:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1750622378; bh=V29bM8FftjdSRqm3wUpJ7wy4cRHgXFcHyBai8F51CXE=; h=References:In-Reply-To:From:Date:Subject:To:From; b=fFFLS+EJMAqmej8qjA+k+tsYgd8EdubGJgrT83QcT/57aniMqs2pjhu2Khl3q57Oj YljesBx8XJPT2Qlv3f3Hj5u/HrxzO1kdjakOhW8JxtyAfaj2UmERvYleMpXjRuhJZX /MdU52W09jvWNLdvMeQ0xgWMxbXvGJeG7I/bEfXQySoSLyBxwtNV/Lv9rwtvKsYgiM PBeTS3D55cx5U1dVOqsXitpSsxba4Ki5WuWPA5OoMZzVW8torXqc9qn4tjwujnK9We UVVJnDpmDBHaaR/OV70owW1U5gYAqiwzsZroFBO+vT/8XaDjuG8FPNkWu8wLrCcX/T sxztK27BslHqw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A9993180086 for ; Sun, 22 Jun 2025 19:59:37 +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=-3.1 required=5.0 tests=BAYES_00,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, 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-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) (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 ; Sun, 22 Jun 2025 19:59:27 +0000 (UTC) Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e812c817de0so2239889276.0 for ; Sun, 22 Jun 2025 13:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750622483; x=1751227283; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=V29bM8FftjdSRqm3wUpJ7wy4cRHgXFcHyBai8F51CXE=; b=PQpU37edLiPAOw309A5c+SPxYv3uYsPs2kxHY0WYhDDhY606K7XrNBtDeAHdZmpEfH u8PerfWTMi/AO4leDjn9CZyzyyJcyAmML4alCOoN64PZ280UN6jv0D+68HZZreoK3eZS hrvPO8R9bb9sCme4VeEFAUJPQ0/m2FOtFzWk57o0K5/qgly8pJtD8QWreJQr1bns9dkz lBfHVfw1ur1/OSiX9QXfCWvje9Wcvs6jQZQgYu1YWI49ZQ2NtZiSdPx4NOeH33WCs1zR CtE4X5NqorI1dlb2zVJRtv6EjoySadRqiw5TC+AaAbWqwrZsw6/NbOW4ImFaqMeFjkkE ljzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750622483; x=1751227283; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V29bM8FftjdSRqm3wUpJ7wy4cRHgXFcHyBai8F51CXE=; b=kg+2M7MQ0j557NovvHWNRnXZ/EZK5rTUxpgKmJoAb4xcrviU5GRt53nyl/ysvyAlmS v022vDACz/5RVNGO7WU5rleftzc2R9pdOD1EOl2701ahXeSqZJyMRukcRXO60d0vvvVG adUurPYtVHF9u5azdNSVd17K3yNgSOPzFJ/5ETvLtx87FCUc75v9Z1YYxfY8S9ybr1JR Tvv1g+d5qZ2TTkJTWSW3/vjZZgtHJOdhFk0wUEMPcc6PTBoSZBs7P+rb89MOmTOCcu01 e/OJaBCAk0QSGZRVwffZ/jvtOsdmYrxXxSo/KjYGoYoiigfKUK0wAX6ZSoFdgBf57DUs uvdA== X-Gm-Message-State: AOJu0YzoaEt6szUKT0JN2e95QDx+HkXIEw/fyk6ARg0InVhLOssfArnS x8VC7QutFe2VG8dV6l75GqCQ6zVMJGysNPSeZGBMsxcat5eaYtc5N9k5OlxXYDRqQzBz0VItjpq IvuOtzryYmODrjbEYqB82aUj1gGvZByOtxg== X-Gm-Gg: ASbGncuL5l2DYBA0Bu1j8Fhk2r/whwroY+S6HmaSWfHMNtjRIk+eGm/DtH/m7ma3kUT a3EP7PMoJ+WD4KCdEQVe1ZWfsrGK25wT/jwo7FqW89Vx4XmEoi/7A4MBoRtGeWGVsvIScf+8kt1 Atl8LOzEu4Vn02I9Azo0ZAvaxKjYJvi9Ftk0h5i6U5UFFVGmtfp5bAVtFrdOp5Eb6PWBRvh2QW4 kU= X-Google-Smtp-Source: AGHT+IE/ZeXVhP7lQ0E4cWZ/k/X5gvhvHg0o3y73pvRduAPRFi3pe2bRj+LKycbk9mh80N5e1BvZLxzWP/4cLbkpTMA= X-Received: by 2002:a05:690c:82:b0:70f:83ef:de07 with SMTP id 00721157ae682-712c676eaf4mr151711187b3.33.1750622482748; Sun, 22 Jun 2025 13:01:22 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 22 Jun 2025 13:00:57 -0700 X-Gm-Features: AX0GCFvMPwpFsVQ3w3qgit_qQbddgQ3qTQkjr3m6JmlqPbJ6oyYDpdWiC30x3Ac Message-ID: Subject: [PHP-DEV] Re: [RFC] [Discussion] #[\DelayedTargetValidation] attribute To: php internals Content-Type: multipart/alternative; boundary="000000000000385edb06382e8f99" From: daniel.e.scherzer@gmail.com (Daniel Scherzer) --000000000000385edb06382e8f99 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jun 17, 2025 at 4:26=E2=80=AFPM Daniel Scherzer wrote: > Hi internals, > > I'd like to start the discussion for a new RFC about adding a > `#[\DelayedTargetValidation]` attribute. > > * RFC: https://wiki.php.net/rfc/delayedtargetvalidation_attribute > * Implementation: https://github.com/php/php-src/pull/18817 > > --Daniel > It seems a common point of discussion is the difference in behavior between internal and userland attributes, so I wanted to clarify a few things: * Userland attributes are always metadata, in part because of the backwards and forward compatibility that those attributes provide - the attribute does not need to exist in order to be used, it just needs to exist (and target the location) when you call ReflectionAttribute::newInstance() to instantiate * Internal attributes are a mix between metadata and a way to plug into the engine. There were already existing ways to plug into the engine (e.g. using magic methods or implementing the Countable or ArrayAccess interfaces) but attributes provided a way to plug into the engine when you don't just want to add a function override, but rather something else (like indicating a parameter should be redacted in backtraces with `#[\SensitiveParameter]`). It would probably be impossible to do that securely with a userland attribute and userland error handler that manually redacted things... * Attributes were designed to have good compatibility - the syntax chosen for PHP 8.0 was, in prior versions of PHP, used for comments - so any code with attributes could also work in PHP 7.4, just without the metadata. Similarly, by not validating userland attributes until they are accessed with reflection, you can add an attribute that does not exist yet (e.g. if using different versions of a library) with minimal complications. * Internal attributes are validated at compile time - because they can be. Internal attributes tell the engine to do something, and it makes sense (at least to me) that if the engine cannot do that thing, there should be an error without needing to wait for ReflectionAttribute::newInstance() to be called. But, the validation of internal attributes at compile time means that they lose the compatibility features of userland attributes, and that is what this RFC is trying to address. To be clear, I think the difference in behavior between userland and internal attributes is a) fundamentally based on the difference in capabilities (pure metadata vs engine behavior) and b) something that should not be changed without significant further investigation. This new `#[\DelayedTargetValidation]` is meant to simplify things, and to partially unify the behavior of the errors - if you are getting any errors from internal attributes and want to suppress them at compile time, just add the new attribute everywhere. -Daniel --000000000000385edb06382e8f99 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Jun 17, 2025 at 4:26=E2=80=AFPM D= aniel Scherzer <daniel.e.= scherzer@gmail.com> wrote:
Hi internals,

I'd like to start the discussion = for a new RFC about adding a `#[\DelayedTargetValidation]` attribute.
=


--Daniel
=


It seems a common poi= nt of discussion is the difference in behavior between internal and userlan= d attributes, so I wanted to clarify a few things:

* Userland attributes are always metadata, in part because of the backward= s and forward compatibility=C2=A0that those attributes provide - the attrib= ute=C2=A0does not need to exist in order to be used, it just needs to exist= (and target the location) when you call ReflectionAttribute::newInstance()= to instantiate
* Internal attributes are a mix between metadata = and a way to plug into the engine. There were already existing ways to plug= into the engine (e.g. using magic methods or implementing the Countable or= ArrayAccess interfaces) but attributes provided a way to plug into the eng= ine when you don't just want to add a function override, but rather som= ething else (like indicating a parameter should be redacted in backtraces w= ith `#[\SensitiveParameter]`). It would probably be impossible to do that s= ecurely with a userland attribute and userland error handler that manually = redacted things...
* Attributes were designed to have good compat= ibility - the syntax chosen for PHP 8.0 was, in prior versions of PHP, used= for comments - so any code with attributes could also work in PHP 7.4, jus= t without the metadata. Similarly, by not validating userland attributes un= til they are accessed with reflection, you can add an attribute that does n= ot exist yet (e.g. if using different versions of a library) with minimal c= omplications.
* Internal attributes are validated at compile time= - because they can be. Internal attributes tell the engine to do something= , and it makes sense (at least to me) that if the engine cannot do that thi= ng, there should be an error without needing to wait for ReflectionAttribut= e::newInstance() to be called.

But, the validation= of internal attributes at compile time means that they lose the compatibil= ity features of userland attributes, and that is what this RFC is trying to= address. To be clear, I think the difference in behavior between userland = and internal attributes is a) fundamentally based on the difference in capa= bilities (pure metadata vs engine behavior) and b) something that should no= t be changed without significant further investigation.

This new `#[\DelayedTargetValidation]` is meant to simplify things, a= nd to partially unify the behavior of the errors - if you are getting any e= rrors from internal attributes and want to suppress them at compile time, j= ust add the new attribute everywhere.

-Daniel=C2= =A0
--000000000000385edb06382e8f99--