Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109673 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38402 invoked from network); 16 Apr 2020 08:16:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Apr 2020 08:16:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 717881804B4 for ; Wed, 15 Apr 2020 23:46:47 -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-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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, 15 Apr 2020 23:46:46 -0700 (PDT) Received: by mail-wm1-f44.google.com with SMTP id e26so3309152wmk.5 for ; Wed, 15 Apr 2020 23:46: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=a1bcxrQ78krlYJq26H9cVYf/ugPlGA8YT0ffX23NJD4=; b=n13fG7yACs8Ng3iR+InDwfiqPfL3BMHuEW6jB4MXqASCctC09ZhniFPVkS3hcg/F7Y xTjwJP1gzFYzvuPVTvOLXKOr4y5tM5pnmaUDPiS7Ozv2yZf+veNCM7ZSk+OikaCJlNQy p1LOzEzwScsgVpPjzgnh5rUI4lQ4gi6OhU0ZSaaTuuKSIn8/Hf9MWsxzzrZah4LPexJX HsWnhXj8uKZPYWfhDWcXwVSEcGy10JCAnt++a0nfySChk//Aum5XASoFtjYdKGBq4U6q 2tYgvub0R8WNlQNHxOyqX7wE8p7VzzUvL3620cw36fIaHfTATq0rx5ODcjgZmHp8GX02 xoqQ== 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=a1bcxrQ78krlYJq26H9cVYf/ugPlGA8YT0ffX23NJD4=; b=Eu1lZ1eMNO7Sf4ljn7A9X7ule/y4GQvL3ztdlKWsSI/oTRPGej2ZP9ew6Y4THQ3cs2 wrzTAEN/n9fWZAiu3beuaJC8vpXpWx9+qBxc9z/6BrKsY1ChyhRb1y29JfPmYv1GWBLe aKZ18yIpCKZRZ6/hIpcVdFAlIo7zhmaSlE11ghZKe0KPDwxFfoh5wyy4zGgZtPrBANXp bd9dtAmev+fktNWNRuc8JHDtezAZM5bL4T2EqgZ7q0dEaWxt3RQy89Ot7CupOVBF2Vp5 6RMGrVULayZSrn6+5uA06//g3SbEMUlLFv0YD5pYZgxy95jllSbkbUk2xdF0tXTZcAAw NloQ== X-Gm-Message-State: AGi0PubAMNWJ6RXq7YQQB4QNIAIydn1LMmrRm8q8znwTXKAInOXAK4Ug PrmCfVnJoSEP0DvC2Ppe1Ym8z7nAwfWAG5VZ2NleLVYa X-Google-Smtp-Source: APiQypJNcAn4NMiLbG10KOVEM6ULEn3N2euNqo1BhiuwHvoRJdofbPRr47BpNdB9FjrOESvIgp0qZTeCrjYtxeJrVYU= X-Received: by 2002:a7b:cf23:: with SMTP id m3mr3135352wmg.36.1587019604515; Wed, 15 Apr 2020 23:46:44 -0700 (PDT) MIME-Version: 1.0 References: <16620f3a-1eb6-437e-aa6f-05e5be2aa713@www.fastmail.com> <231390ee-ff9c-4f7b-918a-4f87a676613e@www.fastmail.com> In-Reply-To: <231390ee-ff9c-4f7b-918a-4f87a676613e@www.fastmail.com> Date: Thu, 16 Apr 2020 08:46:33 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000c7716705a362cbd5" Subject: Re: [PHP-DEV] Re: [RFC] Attributes v2 From: kontakt@beberlei.de (Benjamin Eberlei) --000000000000c7716705a362cbd5 Content-Type: text/plain; charset="UTF-8" On Tue, Apr 14, 2020 at 6:14 PM Larry Garfield wrote: > On Tue, Apr 14, 2020, at 10:42 AM, Benjamin Eberlei wrote: > > On Tue, Apr 14, 2020 at 5:24 PM Larry Garfield > > wrote: > > > > 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. > > Sad panda. > > > > 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 to > > > 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 = > array_filter(array_map(function(ReflectionAttribute > > > $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. > > It depends on the annotation, I suppose. If I'm requesting a specific > annotation by name, presumably I know if it is supposed to have an > associated class. If it's supposed to but it's missing, that's a legit > class-not-found exception/error. > > However, I'm thinking of cases where code is integrating with a 3rd party > optionally, through an annotation. In that case it's a fair question of > whether the class will be defined or not based on whether some other > library is present. > > Similarly, if a bit of code is requesting all attributes (as above) rather > than just specific ones by name, it wouldn't know if a given attribute is > supposed to be defined or not; as written, class-less attributes are > supported. > > I suppose the workaround would be class_exists($r->getName()). Weird but > I guess works? It would have to be documented as a thing you should do, > though, which implies to me that it could be made cleaner. > > That reflection is usually clunky today (true) is to me not a compelling > argument that it shouldn't be made less clunky. :-) > You are not safe from these problems when using Doctrine Annotations either (missing library or class does not exist) and it fails exactly the same way as trying to instantiate something that doesn't exist. I also realized why IS_INSTANCEOF is not the default, because it needs to resolve all attributes to classes to perform the check. This triggers autoloading *all* attributes of the reflected declaration (even the ones not requested), so we felt it should not be the default. > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --000000000000c7716705a362cbd5--