Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109635 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 31250 invoked from network); 14 Apr 2020 17:13:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Apr 2020 17:13:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0D8461804B4 for ; Tue, 14 Apr 2020 08:42:48 -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-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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, 14 Apr 2020 08:42:46 -0700 (PDT) Received: by mail-wr1-f46.google.com with SMTP id k11so14259332wrp.5 for ; Tue, 14 Apr 2020 08:42:46 -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=D1l+TyS80zx5iM3rAf5+MMS9h0DYIFqDg0D13PaGkmA=; b=qDqskS5911h58ehQE59gTaad4ZUyQ47m9C7kB52JCdMDG5KEzSXHoHTQQBAYNpFhal /c+Tx7ZlU5i6vllidlss91wia736AJKsRXzUjCt0R4U8DwR6FxBbRuY2zRyhQ/PJdnoH EunKF1hm7YOJZDU7syu9G0uxxQNQFfo9Ul/Q2Rv3k4TY+JxLpgGnFOGOHSfdqcIYJp8/ VgIdtlXX07BNCr59PpkdhXe836OdMv2lW3lDxd9SdKGzx8j8TSjFJS27NA1jR24jD+hG epdDrYje22ZEXMX1W5XuoPZeZEAJ1IXpRyHMGCnM6IuLEr3J/0UohJRhVODi4HJNP3mr rHug== 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=D1l+TyS80zx5iM3rAf5+MMS9h0DYIFqDg0D13PaGkmA=; b=Z4dNsPiiFcY8WOkZyVOCv0nI892KHujrhnM9DgOtDgoFXYrhIbrqJIFGadjcOOwKJ9 sTRz5J5eu8FMHIr4aHzpjexXRaq1WrTH9krVceZkLeyXZ+sGbXLnkh6BjXvsaEOMLkFU pVAYp6GCtfwxKPbfKpcVkkWgxlf0uUQB99T1ICYeCqt66ANku1YI/vkdKb/a1S/KJ9Np V6mCTwxaBJG5tbvw2B9bAApcA5XtCZ/b3/WaYAlS6wk64qXmJdG4Wvrz90nxBSVyyEZq K1pIjsePGE14JZwRJyjarx57FGe16RxyDCsOnVWt7PJh90xOzVrwR0JEBgHryc/34l9O y4Dw== X-Gm-Message-State: AGi0PubJAKhqRYzKtckVfxgsfaMpKw6CO0iDItxXrodrgoATleDjf2eb 3eGxJPx9BwhPNK7fxnlP7OVx4PH2SDKlBHyvxbPuncMYuyA= X-Google-Smtp-Source: APiQypKC9CNMvolTNX1qg5XHpI16DrL6viqm9SdhckinDb6LbaAMzokZdMUnazruPZZJN3DvjenNAxpY1wzlzp1liHc= X-Received: by 2002:adf:b6a8:: with SMTP id j40mr25779497wre.255.1586878963141; Tue, 14 Apr 2020 08:42:43 -0700 (PDT) MIME-Version: 1.0 References: <16620f3a-1eb6-437e-aa6f-05e5be2aa713@www.fastmail.com> In-Reply-To: <16620f3a-1eb6-437e-aa6f-05e5be2aa713@www.fastmail.com> Date: Tue, 14 Apr 2020 17:42:32 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000e6662805a3420c37" Subject: Re: [PHP-DEV] Re: [RFC] Attributes v2 From: kontakt@beberlei.de (Benjamin Eberlei) --000000000000e6662805a3420c37 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 14, 2020 at 5:24 PM Larry Garfield wrote: > On Tue, Apr 14, 2020, at 6:00 AM, Benjamin Eberlei wrote: > > Hi everyone, > > > > I have updated the RFC with much of the feedback received here, on > Twitter > > and Reddit. > > > > https://wiki.php.net/rfc/attributes_v2 > > > > The following changes were made: > > > > - Changed to support the same attribute multiple times on the same > > declaration > > - Added support for attributes on method and function parameters > > - Replaced *PhpAttribute* interface with an attribute instead > > - Distinction between userland and compiler attributes and descripti= on > > when each of them gets evaluated/validated > > - Reduce number of examples to shorten RFC a bit and expand the othe= r > > examples instead > > - Introduced validation of compiler attributes at compile time using > a C > > callback > > - Offer alternative syntax =E2=80=9C@:=E2=80=9D using new token T_AT= TRIBUTE which will > > be included with a secondary vote > > > > You may have seen me mentioning that I don't want to deviate from the > <<>> > > syntax, a topic of heated debate. As Martin helped me tremendously with > the > > RFC and patches he earned to propose an alternative (including patch wi= th > > prototype). So we will have a secondary vote on syntax being either > > <> or @:Attribute. > > > > Let us know what you think about the changes. > > > > greetings > > Benjamin > > This looks lovely and I look forward to being able to use it! > > Questions: > > 1. Why is exact-match the default for getAttributes(), and "instanceof" a= n > extra flag? I would expect it to the other way around. The whole point = of > LSP is that any subclass is a viable replacement for its parent; if not, > You're Doing It Wrong(tm). It also means that requesting by interface > mandates adding the second parameter or else it will always return > nothing. What is the reason for not making instanceof the default match > and offering an EXACT opt-in mode? > Yes, you make a good point here. > > 2. Regarding sub-annotations, can you still do classes as parameters even > if not as an annotation marker? Eg: > > <> > function foo() > > Or is that also a no-go? > This is a no go because it would require reimplementing constant ASTs, which is as of now 300 lines of tricky code evaluating ASTs and allowing this would also clash with Bar("Blah") reading like a function call, which is confusing and would prevent reconciliation with constant ASTs in the future. > > 3. I see the most common case for attributes being getting the object > version. With the reflection API as currently described, I see two > shortcomings. > > A) I can't tell if an attribute has a valid object or not before trying t= o > access it, which would presumably fail spectacularly. I believe we need = a > way to know if getObject() is going to return a valid value before trying > to call it. I think this is a hard-requirement. > > B) Related, as is getting all attributes as objects looks to be rather > clunky. > > $attribute_objectgs =3D array_filter(array_map(function(ReflectionAttribu= te > $r) { > if ($r->getObject()) { // Needs something better here. > return $r->getObject(); > } > }, $obj->getAttributes())); > > That's gross. :-) Can "get all the attributes that can be formed into > objects" be its own operation? $obj->getAttributeObjects() or some such, > that skips over non-instantiable attributes and instantiates the rest? > I don't see A.) what would you do when the object instantiation fails? You would throw an exception I presume, let the engine throw the regular TypeError, ArgumentError, Error if class not exists that everyone is already familiar with. For B.) I believe you are extrapolating based on your own use case. Working with Reflection is usually a lot of boilerplate, I don't believe we need to have a one liner here. > > This isn't a requirement, but without it I predict virtually everyone > using attributes is going to have to recreate the knot of code above. > > Thanks again! > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --000000000000e6662805a3420c37--