Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121471 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55065 invoked from network); 26 Oct 2023 16:24:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Oct 2023 16:24:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 26D78180538 for ; Thu, 26 Oct 2023 09:24:10 -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,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS20473 216.128.176.0/20 X-Spam-Virus: No X-Envelope-From: Received: from mail.online-presence.ca (online-presence.ca [216.128.176.244]) (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 ; Thu, 26 Oct 2023 09:24:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=online-presence.ca; s=default; t=1698337449; bh=Sa3PNENAqjehuAFdxssMJKkkx2BDMkGp8G/zX64R5Lc=; h=Date:Subject:To:References:From:In-Reply-To:From; b=ZKVypizCZvZZfOMo6qMkFj6H+iMu3LJ5m0DMdFfesJxGjOQFqEr0PArN9ZBqV/G1K d83tpEZysfhi5tdyPD6ic6tYg5NJGwrDv7QRbk4zZ+J9G5aJke/X7z2TGMR20Vsd/3 TxydZordWlsk4Ctui4LvddkSVarDBrJufN8+DPHNXYmtPtuPvoqw4Lzun+ye6U5zS1 o/vhl89jWMqFkuPdsfiJlltr/zyOTrbLh8WKPILtAktRuW6KNwHXO2EG1z/DYVmBb2 0ViBBxklCxyQTbQhCKKFG6JeB1m/VP72LicJ0z/5IBx3ln7Gv1zpWM5/IfmveI7zRF CxdWhD3zw+n3g== Received: from [10.0.0.211] (S01064075c3d865eb.ed.shawcable.net [70.74.109.64]) (Authenticated sender: lanre@online-presence.ca) by mail.online-presence.ca (Postfix) with ESMTPSA id 0F3871055BB for ; Thu, 26 Oct 2023 16:24:08 +0000 (UTC) Message-ID: Date: Thu, 26 Oct 2023 10:24:07 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: internals@lists.php.net References: Organization: Online Presence In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Basic Type Alias From: lanre@online-presence.ca (Lanre Waju) I would like to voice my support for this and i'm willing to help with the implementation. As for differentiating between type aliases and classnames, only one of them can be instantiated. Lanre On 2023-10-26 12:37 a.m., Oladoyinbo Vincent wrote: > 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? >