Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109909 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43966 invoked from network); 29 Apr 2020 10:54:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Apr 2020 10:54:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EFB241804C2 for ; Wed, 29 Apr 2020 02:27:51 -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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE 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-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 ; Wed, 29 Apr 2020 02:27:51 -0700 (PDT) Received: by mail-wr1-f41.google.com with SMTP id k13so1626450wrw.7 for ; Wed, 29 Apr 2020 02:27:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=s7+VocEw4rFljO8RQdFT4a+WzzwibxgVI/rN68MHEdo=; b=oV7ooXvjd5OMUWxpWMYIufgxLKKHT8PMBkuRGHz/Y53LNMR3iVX2Ehkl/L/TaxeYg9 G2pm+WNZuysSo8BqVJwhBDLQ9CHtq1+jzwQiEQ5YW/NodaISw2eiMdPeyGcdigIR1lj/ gY9B06ko9hx5EqPH6UuuTxgPTQF4Ce5IFQUa6ofbmEyOlvbdk7b8aXwlkPMSkA2pp18r N6Byqjh1O5ZKSA9hETgSC7EKxH3Y/NcLDuRdasjNBFuNoEO+7wAlXu8twVQd2LUw3Brj HGKUupA8+QgL3nk3RhC66mczpEFiFD8xo7lMrau0/IAHxVWQAQUZvLBBk1/voOuRD1Wj 6pKw== 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=s7+VocEw4rFljO8RQdFT4a+WzzwibxgVI/rN68MHEdo=; b=aQIdgz3FQT4HSmN6jgZn9mPpqSKRfhA3/IvE5QrQ+qUhYTKQPmk8qGqZz1Uga7pdmI 9BMNFQTbZmrZbV2A4ACIhff+N0ZNi5HcbyHscGjL2VM8285/ThGnMbNlqV3Uv8PdGmgn HBIwM6qVqE4HwGEffe99ldIB1wAJH/pv6Xddikq6dxk0kN7Kaa4XVzj+TMcPxedl75V8 mEjHFZ2h9pZSc2FbTplGGquYGtlrN1nbdT/Nbj/grErdvIKfVgBZ/oh1Xj2TCvfFfYz/ S/bPoJaNSbZ+CBqObpEW0Af7WoTJVMpkMrdr+f02zf5qTVji3+k3CxukQw7zPDv5M4+3 5wTg== X-Gm-Message-State: AGi0PuaDfAjnZI5g05aKP8UxFDC+SGkiQn8u9DmMzCnuj/iO6Z5uCbW9 R1BB708gD9iBv7MMl9cmpeKweiy/aTIC6GODbJZH3w== X-Google-Smtp-Source: APiQypJvfeLhtztNfmDp9FNkHQ5/4UzhaPjRcElD1zoR9kACPV2KOBnoY3VjdcMah82iA29G1Ucrqtc7l54wN3mEVuo= X-Received: by 2002:adf:df8c:: with SMTP id z12mr40810278wrl.116.1588152470039; Wed, 29 Apr 2020 02:27:50 -0700 (PDT) MIME-Version: 1.0 References: <76b72148-4b3a-4a63-ab4c-245439a94823@www.fastmail.com> In-Reply-To: Date: Wed, 29 Apr 2020 11:27:38 +0200 Message-ID: To: Nikita Popov Cc: Nicolas Grekas , Larry Garfield , php internals Content-Type: multipart/alternative; boundary="000000000000d384a405a46a8f9a" Subject: Re: [PHP-DEV] Re: [RFC] Constructor Property Promotion From: kontakt@beberlei.de (Benjamin Eberlei) --000000000000d384a405a46a8f9a Content-Type: text/plain; charset="UTF-8" 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? > > Nikita > --000000000000d384a405a46a8f9a--