Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116192 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1984 invoked from network); 3 Oct 2021 05:52:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Oct 2021 05:52:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DC5631804C6 for ; Sat, 2 Oct 2021 23:36:21 -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,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 ; Sat, 2 Oct 2021 23:36:21 -0700 (PDT) Received: by mail-pj1-f52.google.com with SMTP id na16-20020a17090b4c1000b0019f5bb661f9so6139699pjb.0 for ; Sat, 02 Oct 2021 23:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=tUnbmnbMPo9VlBSqH1x0uF1fb+3o+GARHQMx6FJDvE0=; b=zu8DaRU9I7vv43Xq4b3k13J4zlN1wbZ4mCELRRsKvvvTSeMVqZwBa+Z2BwcOjbPQzg EMFCmN+NRYQ1RG6fnYXO/3fEAm3THaJSzBpUwuZkf9KZR7t+mpAY2/lr0lLedhe5kMsA Po4AhIrgI76ZgPGk1jHJRBNDDA3aXGsfaI4lkhcQBgY6E/jIEd5eaQVO/VxksKW14AbD lCXW+B2UaLnXuF255Xqv3ohe+BAdUlqfgug2A2GygMeI83HZsx1vBcG+QUeUOCG+tDRf MZcGwkr53snAJbeBi4ERL/gzJsv3TVemsrOi0Lv4ZNRrY3leE6ceitRmoxBb427KvO8U X9Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=tUnbmnbMPo9VlBSqH1x0uF1fb+3o+GARHQMx6FJDvE0=; b=sxTKkjqgLm9eRPWeeUlmXx4z2x/Kcfhp3DTLuvfyA5FkehAVRyrSiWRm5X1Rlg5+J9 j6WnOhXBtQoh2IUbBddSlH0atk2zBmdiKa8C+QwVeWVC8HG7AA6E5TdkY5vAm5VwVq94 DR5itkPLlyuWhD3ezuRic0IoB346MSkzZ5hUMFNpsQbS+TOygbvj56K7IUBEU1w9OKIK HdL2i2R9nX/jIInbHbQ3Bmen/cGPVQHWdl8Ux37MlP4IJ5XIEf3U+iUah3JIBa1QAgL4 NFred4qrUu6vP72TACu8piV5O+0vufVCdD5Y7QCCMjHQ7YQ8BNQq0son3knNmeWN++L/ FUhQ== X-Gm-Message-State: AOAM533R8BE80LT+P/ouas7cQgUz+LclkighjAfIfla/3QZmFqWx2gmu C/GhqIQbLbXOknssk22CCyeH/tvdDz8aYDijJDMLlw== X-Google-Smtp-Source: ABdhPJwN2xgL71TN6AMCvXQPkRTcfrCexWGNDNqmMa/Qc0AK170kUIR/tKogh2XqCwpllOyOX1I0zEOTjnarIJ8kQvY= X-Received: by 2002:a17:90a:19d2:: with SMTP id 18mr23022909pjj.27.1633242980232; Sat, 02 Oct 2021 23:36:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 3 Oct 2021 08:36:09 +0200 Message-ID: To: tyson andre Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Unified ReflectionType methods From: andreas@dqxtech.net (Andreas Hennings) Another challenge would be array types like array or C[], or array{i: int, s: string}. And template/generic types like \Iterator. Following the normalization idea, we could add a method getArrayTypes(). But I am not sure how far we get with this, I think there will be a wall somewhere. On Sun, 3 Oct 2021 at 08:18, Andreas Hennings wrote: > > On Sat, 2 Oct 2021 at 16:37, tyson andre wrot= e: > > > > 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 case= s. > > > > > > 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 Refl= ectionType, though of a different form. > > > > 1. To simplify code that would check `instanceof` for all current and f= uture types such as `never` and `mixed` and intersection types > > `ReflectionType->allowsValue(mixed $value, bool $strict =3D true): = bool` > > > > Maybe also `allowsClass(string $className, bool $strict =3D true): b= ool` to avoid needing to instantiate values (weak casting allows Stringable= ->string). > > Ok for me, why not. > I would see it as a distinct PR, separate from my original proposal. > The problem or limitation of these methods is that they don't reflect > the full expressiveness of the type system. > That is, the return values of these methods would not be sufficient to > recreate an equivalent type. > > > 2. To simplify code generation, e.g. in mocking libraries for unit test= ing: `ReflectionType->toFullyQualifiedString(): string` (e.g. `\A|\B`) (may= need to throw ReflectionType for types that can't be resolved, e.g. `paren= t` 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 > > Again, if we iron out the details, it can be a good idea as a distinct > standalone PR. > > > > > The fact that both intersection and union types (and possibility of uni= on types of full intersection types) > > make it hard for me to believe that getBuiltinTypes and getBuiltinClass= es would be used correctly when used. > > Just to mention it, my proposed names were getBuiltinNames() and > getClassNames() to be super clear that the return value will be > string[]. > > For future intersection types, there could be additional methods > getBuiltinIntersectionTypes() and getClassIntersectionTypes(), or it > would be a single method getIntersectionTypes(). Not sure yet which > combos make sense. E.g. array&callable would combine two builtin > types, Countable&callable would combine a class-like type and a > builtin type. > Every type would be broken into a normal form, where the top-level is > treated as a union type, and each item can either be a pure builtin > type, a pure class type, or an intersection of pure types. > > int|string|(A&(B|(C&D))) =3D=3D=3D int | string | (A&B) | (A&C&D) > > If we always use this normal form, then the ReflectionIntersectionType > only needs to have getBuiltinNames() and getClassNames(), not > getUnionTypes(). > > Not sure yet what to do with 'static' and '$this'. > > > > > > Thanks, > > Tyson > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: https://www.php.net/unsub.php > >