Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121466 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22588 invoked from network); 26 Oct 2023 06:37:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Oct 2023 06:37:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0BF2B1804C1 for ; Wed, 25 Oct 2023 23:37:23 -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.2 required=5.0 tests=BAYES_40,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, T_SCC_BODY_TEXT_LINE 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-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 25 Oct 2023 23:37:22 -0700 (PDT) Received: by mail-vk1-f175.google.com with SMTP id 71dfb90a1353d-49dd3bb5348so272956e0c.0 for ; Wed, 25 Oct 2023 23:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698302242; x=1698907042; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=vLvewlypTtTHdgrh9sSHGRrcmUKQ86WTHwe5XGgc4qk=; b=K0uNE7GBmSz2l4mtUE0b/BLqRhh/Q9MlAmBzkWRod1BVsbrO4Ima1Wa9PBUzCd0Hzh KtN1S2/W33NbPaZz3MCoorDmSP3RZIi8kvM7IM6yndHHjhsh5WqSRg38MJPYZD2Wjzvz TFFHfRveg09D2v2BIB0fDXln2IGuwDIZaRq0I4K1DJ2XJhle+Dnob+bjUc6QxsYsMiZ2 XSyPy6VN5KuhjJkK54U9Yo1pzgUFjWtvjYA/LrpM9qp/hNXRRR3yZMNl7SzMqeb81HHK meDNBAdFDQJEvKcRpT9EiFk3FNjPCDEOj7r1Affn9P5HlU4xo6x9vIYjxdPqBabRb8sZ LixA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698302242; x=1698907042; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vLvewlypTtTHdgrh9sSHGRrcmUKQ86WTHwe5XGgc4qk=; b=tD9rrF1A5dSY8P/XRzHXfcKXJD6x7gz+M2FNPUChPdVt9oYJV+mxxe52nW72guIGaq hkbIH2E2is2epYaL5vJ89lfOfEY0Oi4h6ZNbwaYh/KQEe0rXuG6G6iRuXalFRWASMlmC i0Qu74Yx5gxdRcU02U2jF1Olpr5KoYtJ6sd04FVr7b4dp6sbMhwB1uZc1VC0K/NVUi+6 SqkSSCYcOH9Q8VjwS5B0sPYX3v6lCmDHsa75neYRdFNch5FGSIACfIhV+0lqkjQiyhrp NhNNIGBMjeHWUgsxXfIa+vR8QSmpfKH4msVsCygE8sivkPFlMOhPZ4LJazQwXpD1rnlx wGWg== X-Gm-Message-State: AOJu0Yw1Gcs0OQdhoS9mUNhfCEgRDdddBpKy6qDqIfeV4T8OanIjViYW ejmwHeoZUtl6W9piusOntROv5sVXbvXt7Rovw9R2TuI3ivD/Ww== X-Google-Smtp-Source: AGHT+IEgEuUzpC4D4szuURGn5I081IcvFP3EpQT9Udsn4M98p7X7W8naRNG8NGqikl9pTIoccfjv2U1K12RbSGrraGk= X-Received: by 2002:a05:6122:1687:b0:48d:1b20:268e with SMTP id 7-20020a056122168700b0048d1b20268emr17954914vkl.10.1698302241710; Wed, 25 Oct 2023 23:37:21 -0700 (PDT) MIME-Version: 1.0 Date: Thu, 26 Oct 2023 07:37:09 +0100 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000d6ac5a060898cdea" Subject: Basic Type Alias From: oladoyinbov@gmail.com (Oladoyinbo Vincent) --000000000000d6ac5a060898cdea Content-Type: text/plain; charset="UTF-8" Greetings to you all, I will like to submit an RFC on introducing type alias to php. Even though Generics won't or never be introduced to PHP, personally i will like php to add the type alias feature. Type aliases provide a mechanism to create more descriptive and readable type hints in PHP code. This enhancement will improve code readability and maintainability and also to promote type reusability. Motivation: The motivation behind introducing type aliases is to: 1. Enhance code readability by allowing developers to use meaningful type hint names. 2. Improve code maintainability by reducing the likelihood of type hint updates throughout the codebase. 3. Encourage the adoption of best practices for type hinting. Proposal: Syntax: Type aliases will be declared using the `type` or `typealias` keyword, followed by the alias name, an equal sign (`=`), and the type it is aliased to. Sample: ``` type MyType = string; // or typealias MyType = string; // Advance type MyType = string|null; // or type MyType = [string, null]; ``` Usage: Type aliases can be used in parameter and return type hints as follows: ``` function greetings(MyType $message): string { // Implementation } greetings(1); // TypeError ``` Since this is just a basic feature, Type aliases Inheritance (compound type) may not be added, since we are not digging deeper into generics :). References: https://docs.python.org/3/glossary.html#term-type-alias https://doc.rust-lang.org/beta/reference/items/type-aliases.html https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#type-aliases So, What do you think? --000000000000d6ac5a060898cdea--