Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116206 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86592 invoked from network); 4 Oct 2021 07:51:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Oct 2021 07:51:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C74E81804C6 for ; Mon, 4 Oct 2021 01:35: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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.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 ; Mon, 4 Oct 2021 01:35:21 -0700 (PDT) Received: by mail-ed1-f52.google.com with SMTP id p13so33555581edw.0 for ; Mon, 04 Oct 2021 01:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vo+IVjQnUdOTFIMN86LIV4ZL7yHQBOcOBWJkKeoXIhs=; b=DqrYQ07xF4Yf+BJqJraKQ0nWxRYig30lTcrcjiiagjsU3U5llxSQP3B0qrgdaaZyaA 7vOCzNO8vLz+hFuJ3u9PVyq7TiGaV6FGLLa9GbrN7czcK57EyZdVd46XniRvteNo4lDv +y0tJN6DbVWDexp4jsKzl2FMDZdN2gPCeeGZOVqA4hG3bjQQ+q8BTG90/Tkv2ZDfYvu9 BzxKTFy856ATfGHXnBNT01OeuQEl92i7M1fwUlbaxwpkvtjpQb83+ZbAgaBOlPDJPCNw uPGRFGrK7xBAvtQFnOtuI0Ed5QmSN54oBzmsK27clpPTxU/CXXhafFuNjtWYa35fNDxC 3lxw== 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; bh=vo+IVjQnUdOTFIMN86LIV4ZL7yHQBOcOBWJkKeoXIhs=; b=gUKW3cIkD93MafKb78SavvbizvknyJs9eWig3qvp5xKtQ58hUZbsjMfWYFyEOQhmiG t18wGrcfuIbOZ71Z0WNt2hi5AZKqmajSiwaWNTSPD0QUDkmHWApD77peb5ReqLZkQxSN nkIrr4JAmhRpFQK69QCjDIhgl7Eiizn4i6DOxGzqnxzkAJf1QcwhlpRx7FMmDdo4pgDC Au6+J/gx45FY1OFfgV45kq4QoNlyA1Inq6sUR3BfHwny7lfbXJ3BYxxGsCcUcsfWQCn9 KF18izr/0UwF+AVIAMpGZua2YMQNZzGlVPcfwdDwYQnnmDqZfSbu1Fos7iJVrGdHN4OT /9MA== X-Gm-Message-State: AOAM531xMgbjBieLiBpKzCX5fFupPtJ6dgTzHZx2erpxHbGFPkjiLHty ZMFx534tttDekVVUG5DJ+iZDcMN7jMjeHrnp4YqXcjtz X-Google-Smtp-Source: ABdhPJy5YHvk7Lqnw6bx/LoSqYJ/7SY8Y/XBSY8mHWgJErX8KZFIw6gZIpTxOcrzDRYJKZUOwVKGPkcCfIN4jElPrEc= X-Received: by 2002:a05:6402:5191:: with SMTP id q17mr16844966edd.332.1633336520135; Mon, 04 Oct 2021 01:35:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 4 Oct 2021 10:35:04 +0200 Message-ID: To: "G. P. B." Cc: Andreas Hennings , PHP internals Content-Type: multipart/alternative; boundary="00000000000014d77d05cd82cb63" Subject: Re: [PHP-DEV] Unified ReflectionType methods From: nikita.ppv@gmail.com (Nikita Popov) --00000000000014d77d05cd82cb63 Content-Type: text/plain; charset="UTF-8" On Sun, Oct 3, 2021 at 3:42 PM G. P. B. wrote: > On Sat, 2 Oct 2021 at 00:54, Andreas Hennings wrote: > > > 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? > > > > -- Andreas > > > I don't think this is a good idea, at least in a form like this. > I understand that the ReflectionType API is cumbersome but I don't think > merging everything together makes a lot of sense. > Want does need to know if one is dealing with a Union, Intersection, or > single type and conflating the APIs is IMHO a bad idea as it doesn't > consider future extensions. > And I am not talking about more complex composite types such as > (A&B)|C|(X&Y), as those will be handled within the existing design, but > potential additions to the type system like function types, literal types, > generics, etc. > > I also don't really understand what the argument for removing instanceof > checks is other than more generic code which works, but if this breaks at > the next type system addition, this seems rather pointless. > Agree, I don't think this suggestion makes sense. The current ReflectionType hierarchy is specifically designed so you have to do those instanceof checks and deal with the different kinds of types we support. The ReflectionType hierarchy isn't complex for fun, it directly reflects the complexity of the type system. As the type system becomes more complicated, there will be more kinds of types that are exposed through reflection and need to be handled appropriately. I am fine with additions as Tyson suggests them: Methods that work across *all* ReflectionTypes. The proposed methods do not fall in this category, as they don't hold up for intersection types in PHP 8.1 already, let alone future type system additions. Regards, Nikita --00000000000014d77d05cd82cb63--