Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109637 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38317 invoked from network); 14 Apr 2020 17:43:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Apr 2020 17:43:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D25211804CE for ; Tue, 14 Apr 2020 09:13:32 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 14 Apr 2020 09:13:32 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 5901C6BB for ; Tue, 14 Apr 2020 12:13:31 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Tue, 14 Apr 2020 12:13:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=1FTKsl xy77OqZlAGn0WjQlWtMByFmpYsl3xslm1U6WI=; b=WO5ecVd3p4CzevHyrvM6Ro GHP2RP+CFG3EqsN0kkki2MYhCxgZPeBYwyvV9ly02Y7gGsBdolGIQXA/DCnR4Zwo EhprhQNTj8d9ZeFBwR2Qup423fqq08XTRxxK8rJL8V5vMRwm33S1LshIZMBbjTfy BwYn9242ABksIF7ksr9v1PBGk/FesFA/YW5F375uRochJkpvN7IID6w2WZckNKXU Oo0xGPxUxMq5U31wI+UF76aQKbeNeqewqjJOsticPVNCK7QsbsU9j6UvM46MEBOH 4efewbEZC+WDHz28YEEqBhr7bKdwklKlkXQJkkkA9nz7BnqXM0befPRR3LoMw93g == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrfedugdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgr rhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 9C27414200A2; Tue, 14 Apr 2020 12:13:30 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-1130-gd0f8b30-fmstable-20200414v1 Mime-Version: 1.0 Message-ID: <231390ee-ff9c-4f7b-918a-4f87a676613e@www.fastmail.com> In-Reply-To: References: <16620f3a-1eb6-437e-aa6f-05e5be2aa713@www.fastmail.com> Date: Tue, 14 Apr 2020 11:13:08 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Re: [RFC] Attributes v2 From: larry@garfieldtech.com ("Larry Garfield") 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. :-) --Larry Garfield