Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116194 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25587 invoked from network); 3 Oct 2021 13:42:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Oct 2021 13:42:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7D02E180002 for ; Sun, 3 Oct 2021 07:26:26 -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.0.0/20 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (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 ; Sun, 3 Oct 2021 07:26:26 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 864285C00E8 for ; Sun, 3 Oct 2021 10:26:25 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Sun, 03 Oct 2021 10:26:25 -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=fm1; bh=YBns2g oHITa23TyhELLjNeXoxmNro22gYlCzDc1ADIo=; b=Y6c5HlQg27oRXK0g6yb3Dh PMhhV5jaLXvVpRPVv8HD8RHH7hfuM2iqpa2I3mnvTpwCqdjN3s3LFJ+t8j1YYuNS 98rsavPFQHTnuL1eB8mBEWEBSfeJsANNAjpJIysYWTL68OPsqS2WF623XqFTCaFs kqbuFfZCLEUI5CXqp5Ib4sHdLDHI32gJ1fb29pRRAUShtXO6PYVoVeOvxJPtLek9 AtJx8maWVy/ZQ12mN931SFn+Jqy7SoFgKsPCrpMc58ZWGxbbE0phpg5Bv98q5Mf1 IJGuRZ3868Tj/HFGBap3VZBKmyrnFS58QkoKHilKEMeh108KjlIhsQSW7R6FuVpg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudeltddgjeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 5EB65AC0380; Sun, 3 Oct 2021 10:26:25 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-1322-g921842b88a-fm-20210929.001-g921842b8 Mime-Version: 1.0 Message-ID: <861db10e-a407-40d1-9346-af2fd634e47e@www.fastmail.com> In-Reply-To: References: Date: Sun, 03 Oct 2021 16:26:05 +0200 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Unified ReflectionType methods From: larry@garfieldtech.com ("Larry Garfield") On Sat, Oct 2, 2021, at 4:37 PM, tyson andre wrote: > Hi Andreas, > >> Hello list, >> I would like to propose new methods for ReflectionType, that would >> allow treating ReflectionNamedType and ReflectionUnionType in a >> unified way. >> This would eliminate the need for if (.. instanceof) in many use cases. >> >> Some details can still be discussed, e.g. whether 'null' should be >> included in builtin type names, whether there should be a canonical >> ordering of type names, whether we should use class names as array >> keys, etc. >> ... >> What do you think? > > Relatedly, I also had different ideas lately about new methods for > ReflectionType, though of a different form. > > 1. To simplify code that would check `instanceof` for all current and > future types such as `never` and `mixed` and intersection types > `ReflectionType->allowsValue(mixed $value, bool $strict = true): > bool` > > Maybe also `allowsClass(string $className, bool $strict = true): > bool` to avoid needing to instantiate values (weak casting allows > Stringable->string). > 2. To simplify code generation, e.g. in mocking libraries for unit > testing: `ReflectionType->toFullyQualifiedString(): string` (e.g. > `\A|\B`) (may need to throw ReflectionType for types that can't be > resolved, e.g. `parent` in reflection of traits, keep `static` as is) > > (The raw output of `__toString()` isn't prefixed with `\` (e.g. > `A&B`) and can't be used in namespaces > > The fact that both intersection and union types (and possibility of > union types of full intersection types) > make it hard for me to believe that getBuiltinTypes and > getBuiltinClasses would be used correctly when used. > > Thanks, > Tyson I think at this point I prefer this approach, for the reasons George mentioned. "Here's a value, is it going to work if I pass it to this type check?" is a nice and generic operation that would extend gracefully as the type system expands. It also dovetails with the pattern matching that Ilija and I had been working on, although that's now stalled as he is unavailable for personal reasons. That is also largely a "here's a type def, does this value match it?" check, but with a few extra bits. (If someone wants to take over the code side of that, please let me know. It's over my head to implement but we have a fairly-complete design and the code is partially done.) --Larry Garfield