Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120100 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91028 invoked from network); 21 Apr 2023 10:50:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Apr 2023 10:50:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B0FF6180211 for ; Fri, 21 Apr 2023 03:50: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, 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-ua1-f47.google.com (mail-ua1-f47.google.com [209.85.222.47]) (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 ; Fri, 21 Apr 2023 03:50:21 -0700 (PDT) Received: by mail-ua1-f47.google.com with SMTP id a1e0cc1a2514c-76fc767acc2so187332241.1 for ; Fri, 21 Apr 2023 03:50:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682074220; x=1684666220; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=uK7O84RQQ8AWdztLkgXouCxRCt0SlMMxUcsmTmc7xBU=; b=BSnAgVTgJD8G6t3Dh4CP/ueUo0yhe0nyQiKLr6y6KgWuIXFyB+16SpqlSeQMj7fmKu KJac8YPgcwshiBr1SjSNUaf/nGS0jjmCwTpY2Ppw80/S6WbkTszSEt64FyCy+iYNzJQj tw5BkDYwlMNqpkCmRA5aE01S2+/Q4wu5dh61A6re9tMBsbP0nhP7fa/mo4vNs9OwX9zN ubB8AmI69kiKHYKcuSvhe5UnGBY3LB5Mac8HzAWxC9WZTaNd/UScJwOW8xWX5P4dUEYC URBTGmOESib9Id+1dI5dvbTB85d21m+FVhb/v4tKDMMbZUjoKjR5JTnwfmmloka+FOfa WN7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682074220; x=1684666220; h=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=uK7O84RQQ8AWdztLkgXouCxRCt0SlMMxUcsmTmc7xBU=; b=QIwwsFGURIUqUxgvi9Bc6mCil8bRtHdrfUqGhaj47Uv7xdJoFEdXVdojYwbFEPF6Ja 5iQo6u2C8bDPcm/3qGGyQnyQsLsyngi0Ia+0iHshLSnEhXgpT3lm/4gAq2PArDCbqdyj eI21loAQ2AmpRx+P+mylpKUwfrPLzXbjDGE5ILqKfkQRTwpOISfmpkL434zcu4rLLjos ll+qog4avUYcYm9dUPD4muWunEs/rgNPy3G8pNB/5H5BqQtJbwrVm39ZzIpnKCVOgwf/ azDoSzXlcjrCO+ta4PKg1pjbtKtVXzXpuP8tItWiUOJmgTQfXt1cDS126TNbv5Pl+a+Z j7+Q== X-Gm-Message-State: AAQBX9cfC8TAzcZ1ELX8AQrGBNuK4acaDE1nHQL9P5LOckXF92FneT51 SMUIPUKA44nuY6P1pzh5LA2kgiSYkVMA3bb3NKvS4GYwV+g32Q== X-Google-Smtp-Source: AKy350b18Xztvex5wHZIlBesB8IGdsBGsNFwPLXbGxPMPIsICQTlkqGEsB8ITBQMIqLXp7fOF5Tqb6X5M6nKJRPGjDU= X-Received: by 2002:a05:6122:a1a:b0:440:3bf2:44e8 with SMTP id 26-20020a0561220a1a00b004403bf244e8mr1702863vkn.0.1682074220533; Fri, 21 Apr 2023 03:50:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 21 Apr 2023 07:49:44 -0300 Message-ID: To: Robert Landers Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000669d1605f9d66c69" Subject: Re: [PHP-DEV] Expansion of PHP Symbols? From: deleugyn@gmail.com (Deleu) --000000000000669d1605f9d66c69 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 21, 2023 at 4:10=E2=80=AFAM Robert Landers wrote: > Hey Deleu, > > I ended up on this list in the first place because I wanted to figure > out how to implement type aliases. I can confidently say why no one > wants to touch it with a ten-foot pole: implementing this will require > refactoring the entire type system. There currently isn't a 'type > table'; supporting type aliases will probably require one. Hey Rob, thanks for this info! I just have some small follow-up for me to make some sense of it. What is fundamentally different about Type Alias as opposed to something like Enums that was recently introduced? ``` enum Options{} class Options{} // Fatal error: Cannot declare class Options, because the name is already in use ``` What I would expect here is ``` type Number =3D int|float; class Number {} // Fatal error: Cannot declare class Number, because the name is already in use ``` When the engine needs to know about a type alias and it's not in the symbols table, trigger autoload. When the type alias is registered, check if it's value matches what was sent (Type checking). I can kind of imagine the implementation of this could be somewhat awkward because it would involve `instanceof`, `is_int()`, `is_float()`, `is_string()`, etc - meaning we don't have a unified verification system/syntax that encapsulate types and scalar types all at once, but it's not like we have infinite scalar types so it's still doable? > I was able > to hack something together that used the import statements as a way to > work without that much changes (I never got autoloading to work, but I > suspect that was my unfamiliarity with the code, not that it was > impossible): > > use int|float as Number; > > at the top and it would work with fairly minimal changes to the > engine. Anything more complex or different required a huge > refactoring. However, from previous discussions, when that syntax was > brought up, it was shot down. It appears that people want code-wide > aliases, which goes back to refactoring (to the point of > re-implementing an entire type system) and people can't agree that > it's a good idea in the first place (i.e., what if you think int|float > is Number, but some other library has only float aliased to Number?) > and then that can be solved via imports ... but how does that work? > What if you think `\Marco\Deleu\Stringable` is something that works like PHP strings, but it turns out it's actually a math interface that only works with numbers? I know I'm exaggerating, but it's only to make it more obvious that namespaces have solved that problem a long time ago. A library can use `\Lib1\Number =3D int|float` and make use of it internally and I ca= n also import that. If I want to import `\Lib1\Number` and `Lib2\Number` simultaneously, we have ``` use \Lib1\Number as Lib1_Number; use \Lib2\Number as Lib2_Number; ``` They can be different things and mean different things and be used differently. PHP has "solved" this problem ages ago. If users want a standard meaning for Numbers, PSR can do that. If there is consensus on what `Number` should be, perhaps we will have a `psr/type-aliases` package that defines common type aliases and everyone that wants it can use it for interoperability. Sorry if it sounds stupid or obviously broken, I really am just looking to understand where my rationale flaw is. --=20 Marco Deleu --000000000000669d1605f9d66c69--