Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111996 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 3876 invoked from network); 5 Oct 2020 00:25:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Oct 2020 00:25:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 197341804AA for ; Sun, 4 Oct 2020 16:38:15 -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=0.1 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, 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-Virus: No X-Envelope-From: Received: from mail-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.42]) (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, 4 Oct 2020 16:38:14 -0700 (PDT) Received: by mail-ua1-f42.google.com with SMTP id d18so1952396uav.4 for ; Sun, 04 Oct 2020 16:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Fv25yDAWkVD8ScL7sOT/2r3CNAF4UMeSkxylc5RVLfI=; b=S6nyJVU93Cii+7M/4d/9QP0IR/ETd1ABZWtQIpBY0WKfblZMDXjGcmRoPVX9U1+zS9 JVE4XWS4EwEc649KLzIPBdz8HF4JsVDDXeB3SjLvtFLzJxX+GdptwDVxdfjkrkPzTW0E rLcI5yJ/muvMJc8q5bMdyEdZVaKBfHxTWCSlhSNOv4RrZAbS5hi47CdufVR7qZtmLeFC k5POOv0/yMsqiyYmG/gfMQrkg9evcLoY8d04xIn4MSaidVOyHGCvqK6jZN6A6+6E8iaf Muk5pOMSwulDLVUXpbd05KG3E3qtwCnaeXIIkwJ5K7mF1jR3kRNMF7kC33+MMVHMyhAl v1OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Fv25yDAWkVD8ScL7sOT/2r3CNAF4UMeSkxylc5RVLfI=; b=imAWti3h9iqxPoaRqku3ykfNIjPqOC2j1nWvxddwzgmKKjk00SIDqixTM+C5CKYGY7 3hUkY5+qhS4KNgLF7F6ZhF11t173ETHSE8W42b6qq6SZgiDcOkTp/z75H5w7jaa8xvfC v/HjozYqxezoFsIbphsKi2HBqCbzdiME6d6dai2DqBVvkg2QzNd30hltr6NlbzE5BZft k46km+GkJ8vgESGRGa+pIHcpGsblypuCoYjdkG1FyE6sgSzevMZi2PpHKTLHqtqXxpfU LUzDdje0EU+WKr8bhYnU2z3zLh7LcktBPinwgWZDduo89w1zvXbb6aWNaU1OgFEi0JUF XzzQ== X-Gm-Message-State: AOAM532w+aIzM5tLQRqmFG6uYKDvPNJSHy0vVTdP9r8tJno5j0HxDYXZ 6ZtHFAcm8GkaRVSSXMVB3mV2e5/IWH+1qB7MbpYvry9jQOU= X-Google-Smtp-Source: ABdhPJwMMJhlSYXHQREL9bujsIz/dbXkHnNvQ7MjIS8lQ9S3H3bHEnrYaci/dvGtz1tY9Ob1tLvmZjdA0YFb1ysaMUY= X-Received: by 2002:ab0:6709:: with SMTP id q9mr1861038uam.142.1601854692001; Sun, 04 Oct 2020 16:38:12 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 5 Oct 2020 02:38:01 +0300 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000e60a5c05b0e0dbc8" Subject: Literal types RFC From: bogdanungureanu21@gmail.com (Bogdan Ungureanu) --000000000000e60a5c05b0e0dbc8 Content-Type: text/plain; charset="UTF-8" Hello internals, Since union types have landed in PHP, this allows us the possibility to have literal types support as well and I would like to hear your thoughts about an RFC for it. I think a feature like this would greatly improve the way we model our code in very common use cases. For example, let's consider having a function that returns the status of a post. ```php /** /** @return "draft"|"published" */ function getStatus(): string { } ``` Would become ```php function getStatus(): "draft" | "published" { } ``` Of course this could become quite messy if there are more than a few literal types, in which case separate RFCs could be created for type aliases and valueof/keyof features. I would also like to mention that I also worked on a basic implementation for the first phase of the implementation; it's nowhere near to be completed, but I think I can finish it with some guidance/help from you. Regards, Bogdan Ungureanu --000000000000e60a5c05b0e0dbc8--