Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109687 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32307 invoked from network); 16 Apr 2020 15:58:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Apr 2020 15:58:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A16AE1804B4 for ; Thu, 16 Apr 2020 07:29:11 -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,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (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 ; Thu, 16 Apr 2020 07:29:10 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 272C65C030A for ; Thu, 16 Apr 2020 10:29:10 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Thu, 16 Apr 2020 10:29:10 -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=yuVI2O WuhgrwvkD0W40nhL+NpwrOkX7u4IQTWSFP9ow=; b=MwpRRolPH/DLNf/RYk4UgS Ldzox2q0QwVJpYxpgZ6cAF3739sNQxH8R59sQT2o0xc6p5AsvJkfZklUrlA2Mesu rTKSQ7Kpg0VXWc/XOn1E0dXTxfqegsP4hIbpH5rSsuwoOYjXgIlheqZ1TV0BaHw2 u78GDQbnC3e0K4Qar+a/rnRiYQWNFVjIyUfGpfvHfR1776lS14kU3yIP0L2gntAp HvPj3JxYRWclPXUBw78GZAOhvYbMEavVrhmwPkUPRUuFOrBnOBF8RMN6zSJdbJhz 68ECG6fCfI+DNtT/LjZMZpy8yQPS/iJsKbYTejJgNeOi+N+QQCNU0rsNAK4TGOfA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrfeehgdejkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgr rhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 87EF714200A2; Thu, 16 Apr 2020 10:29:09 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-1131-g3221b37-fmstable-20200415v1 Mime-Version: 1.0 Message-ID: <11f35e10-5bee-4b28-b784-69f7f5f2f11e@www.fastmail.com> In-Reply-To: References: <16620f3a-1eb6-437e-aa6f-05e5be2aa713@www.fastmail.com> <231390ee-ff9c-4f7b-918a-4f87a676613e@www.fastmail.com> Date: Thu, 16 Apr 2020 09:28:49 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Re: [RFC] Attributes v2 From: larry@garfieldtech.com ("Larry Garfield") On Thu, Apr 16, 2020, at 1:46 AM, Benjamin Eberlei wrote: > > > > 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. Ah, valid. I suppose that's an unavoidable result of allowing non-class-mapped attributes, which means anyone building on it is stuck doing their own class_exists() check for everything. Sad panda. (Still very +1 on the RFC, just sad panda about these details.) --Larry Garfield