Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110003 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34439 invoked from network); 5 May 2020 14:00:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 May 2020 14:00:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2DCD71804F3 for ; Tue, 5 May 2020 05:35:50 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 5 May 2020 05:35:49 -0700 (PDT) Received: by mail-lj1-f182.google.com with SMTP id y4so1411497ljn.7 for ; Tue, 05 May 2020 05:35:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kzZhqlWa6QcLlKPqMsltcJF1FIRWpNRB3NrAaGHdmdw=; b=AqCSoo1Ax7iQFYnIBdyYOJGBWMw1xaH2f24lJ/t1XbfCsecga0QuwqkkUHniwL8L9M sPE/BnXn079v1YuAlEx6DRHzq62afMBKNnTrrfmbafyLQ/yrh9vJgJJXc+7NwCy4HiGG +6XTUNgLi32W6Auyj2hKj5K8uASEs0Z79mnJ1dh1t1UhTEUv3e4He4hWfE8ScgMmXbzS n6XnYroeccOYmYeb2Nw7ioAmCoXNcF+7dG7IWA9GaTdPesAtv2tkfzTs8q7TSY12NeMb gChKJnRSinsodJafW9ju16fJGfCjueEh2MJ5h5h4d12Z/LQEr3tkqFCuYO4OGDEtzcr5 jhAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kzZhqlWa6QcLlKPqMsltcJF1FIRWpNRB3NrAaGHdmdw=; b=AoIbihG+yDah4qb4t1csUVcw5eJfKU+e1cq2H8jrVYsFZsHqwj9uV5o4yyx1dni3uY EUHchx7j5epovFA/XZxlm11KMH9FM18MlT9lvSe4c1AmrvaNIeb1NohdhShylsBV030C x5OImJMfjiO1u+1PV9nP4w2oE7tVkWBbaAhMwLDl5xcO5nbzAQcKB2jVMgwuKz7oouI/ mD5juCD1Ucl29FzIKTCwkB6v69t7yXs4CQ/mj2mRDmvlhB54i/5lAqCy3SiP3vkhR2Fm 14/zOfo8gJ8CS5N1KBdEYUqKm4oLlitmAItRJGaGrbmiSD+ET9BC7yEoJdvrLzMZgPNA xnZA== X-Gm-Message-State: AGi0PuZXokOyR3Sy+iRI7aVf5Vgcnenj+COLc40K/9LgHFA8E0cKIuWk gfsWnO1sRV7S0KFFsJYUPcdr+SHNxP56wlHuEBc= X-Google-Smtp-Source: APiQypJGNi3s9lWzvF7RVyAdG8A7nwinsZIHF3EJlJwZiTVIIo5hjsQDpIgraYpYF93nuxuR9sZrlAoV4oPA7YGJFHY= X-Received: by 2002:a2e:9a04:: with SMTP id o4mr1671858lji.117.1588682148103; Tue, 05 May 2020 05:35:48 -0700 (PDT) MIME-Version: 1.0 References: <76b72148-4b3a-4a63-ab4c-245439a94823@www.fastmail.com> In-Reply-To: Date: Tue, 5 May 2020 14:35:31 +0200 Message-ID: To: Benjamin Eberlei Cc: Nicolas Grekas , Larry Garfield , php internals Content-Type: multipart/alternative; boundary="000000000000194d3005a4e5e31b" Subject: Re: [PHP-DEV] Re: [RFC] Constructor Property Promotion From: nikita.ppv@gmail.com (Nikita Popov) --000000000000194d3005a4e5e31b Content-Type: text/plain; charset="UTF-8" On Wed, Apr 29, 2020 at 11:27 AM Benjamin Eberlei wrote: > > > On Wed, Apr 29, 2020 at 11:07 AM Nikita Popov > wrote: > >> On Wed, Apr 29, 2020 at 10:56 AM Benjamin Eberlei >> wrote: >> >>> >>> >>> On Wed, Apr 29, 2020 at 9:47 AM Nicolas Grekas < >>> nicolas.grekas+php@gmail.com> wrote: >>> >>>> > I think it might be best to apply to "both" and provide an >>>> isPromoted() >>>> > method on both ReflectionParameter and ReflectionProperty. Any code >>>> that >>>> > wishes to validate the allowed positions of an attribute can then skip >>>> > properties/parameters that report isPromoted() as true, to avoid >>>> reporting >>>> > false positives. >>>> > >>>> >>>> That sounds good. Deal on my side. >>>> >>> >>> Just to mention, any approach here potentially conflicts with anything >>> we consider for potential target validation on attributes, i.e. declaring >>> for an attribute that it is only allowed on a property OR an argument. >>> >>> At the point constructor promotion happens, we can also not look into >>> the attribute to see if its target=property or target=parameter, because >>> this would require triggering autoloader. >>> >> >> Does it really conflict though? Can't the target validation just ignore >> invalid attributes when promotion is involved (or rather, only check that >> the attribute is valid for either property or parameter, but not >> necessarily both of them)? >> > > Since target validation would happen on ReflectionAttribute::newInstance > alongside other validation already proposed, this means there is already > the ReflectionAttribute instantiated, so we could only avoid throwing an > exception, but the code might still get an attribute returned that doesn't > belong there. The technical problem here is that we defer the validation to > newInstance(), and not already during getAttributes(), to avoid > autoloading. It looks like we can either have target validation and have to > move validation to Reflection*::getAttributes(), or we can't have the > validation. > > The same problem would essentially appear with a "repeatable=true/false" > feature that prevents the same attribute from being declared multiple > times. Its validation should also better be done at > Reflection*::getAttributes(). > > Maybe to allow for access to attributes without validation we should > instead have > `Reflection*::getAttributes(ReflectionAttribute::FLAGS_NO_VALIDATION)` and > don't defer validation to newInstance() by default? > Performing validation when the getAttributes() call is performed does sound reasonable to me. We can also add a class flag to perform this validation only once (if it is successful), so the cost doesn't have to be paid by every single getAttributes() consumer. For the purpose of this RFC, I've now updated it to say that attributes will be applied to both properties and parameters ( https://wiki.php.net/rfc/constructor_promotion#attributes), but with an explicit note that we should change the behavior prior to the PHP 8 release if it turns out to be problematic, e.g. with regards to an attribute validation feature. I think this is something of a detail, and we'll be mostly fine whichever way we chose, but it's hard to say right now which option is best, in particular with regard to future attributes improvements. Regards, Nikita --000000000000194d3005a4e5e31b--