Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121467 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34271 invoked from network); 26 Oct 2023 10:46:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Oct 2023 10:46:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9AF131804A7 for ; Thu, 26 Oct 2023 03:46:20 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (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 03:46:20 -0700 (PDT) Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-586a516755aso368959eaf.0 for ; Thu, 26 Oct 2023 03:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698317179; x=1698921979; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=W/DV5RPFudiNTG43dUMecBOUZTZ25sGDRAiYXPkohZE=; b=fTeUGKy9QQiGsq3LrPrpqn3Cuzm3QM6xEjurm/sHA2fbdIZSEPC70SE3x61VY/BPtK HFd30XJqadlKRcCub0Vf75BmKcUkfNpzEo+1uQVLkSWLlTrr42PorIpTL+ns6P5MUom5 JQCn1cZ8MCzy5gFQFGqKMmZMjkDs3mH/ntqSCKOidSdq9ENMkbrPk3Niq3DBtKhYWS3F CxvcX657TNBewYLC1qNVAeF2fQSMOkMyf9m5R3rxFf1opJzC/D7jniSvfUuN7kelNR3V p7b61loo8+QchPuNMSO/aHrTKmU+yvi3JBVH9IGPqE5E8KwC7x4sV1qoVuFiDYpuub2v 3FrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698317179; x=1698921979; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W/DV5RPFudiNTG43dUMecBOUZTZ25sGDRAiYXPkohZE=; b=jzUMgyGwwLfZNO9UUYPM/nGyG2XKSyrzPRQzSYQgK+bXXRxc93JxKemc/uo2ag8uB0 AYGfnJ61qkDkuQe9H7s5qv6G8WgwdbGHrw53y3hUJdpZ73JNB+wS4dlIPpo4xX6q2L3T t+sjvDwQAD/h6IRa/vLGrrQoBkXNYWa94YjOGfz/nUnVMcxtTIvLuRsDk7L0OA3VdgoH +pqrqlcnOROteoNRnq0tq/mABBZJpyIFBbdKhCp5w+WRojAVeAFNbwwklrOlnK83kHjt axo3BzBKpeuSKKJq4JxIF4NoysGW4nZT43snkDLQEIVzj6cwRJrxqZ9tPq5uCN5pph2i pDmQ== X-Gm-Message-State: AOJu0YzPkOXh5D1fFr5b/C6Ly37EGr/n/fc+EJ3uasxW3HkcmPajdrKK iQjOo3a++BcYuuaSz6DkQ/W0PRF0b+IPW9O2c+pbYLP57xjIFrUT X-Google-Smtp-Source: AGHT+IGRf1ueNVF0QK9E4MfCuGREDweFtrzqeF8R797PFSu3mZnhI68OOkZFa6j+9M+M3hnDZcX7gYkwfPjjLK3gI6I= X-Received: by 2002:a05:6870:ab1a:b0:1e9:88e0:b8ba with SMTP id gu26-20020a056870ab1a00b001e988e0b8bamr1851063oab.29.1698317179240; Thu, 26 Oct 2023 03:46:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 26 Oct 2023 12:46:08 +0200 Message-ID: To: Oladoyinbo Vincent Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Basic Type Alias From: landers.robert@gmail.com (Robert Landers) On Thu, Oct 26, 2023 at 8:37=E2=80=AFAM 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 wi= ll > 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 an= d > 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 (`=3D`), and the type it is ali= ased > to. > > > Sample: > > ``` > type MyType =3D string; > > // or > > typealias MyType =3D string; > > > // Advance > > type MyType =3D string|null; > > // or > > type MyType =3D [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? Please make these aliases either per-file (easiest to implement with the current design of types, in my humble opinion) or able to be namespaced. If I have an alias called Currency and a class somewhere else called Currency, what will happen if one file is included before the other? How will I specify that I want an alias or class of the same name? Will I need to alias the class, or can I alias the type alias? How will autoloading work with composer? Will a file called "Currency.php" be needed to discover the type alias? Robert Landers Software Engineer Utrecht NL