Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121476 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87729 invoked from network); 26 Oct 2023 22:36:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Oct 2023 22:36:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 160FF180506 for ; Thu, 26 Oct 2023 15:36:34 -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-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) (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 15:36:33 -0700 (PDT) Received: by mail-ua1-f48.google.com with SMTP id a1e0cc1a2514c-7b6187af71aso153274241.1 for ; Thu, 26 Oct 2023 15:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698359793; x=1698964593; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=iLh8agMtrcsn72KEkgzj3KZJxRAWq8B9wJ+Ht1+nXGo=; b=K1pqneGiC436u/HaKDVXJUunSyrn6OrMPM5uTCmH5lY8GVdzpvR/vqUbxn1TOV/q/a TMtKQ7AB1lunbB8FbHy1hwGlMV7szFUtTyECr1FBfwaeUm73UN4hNC+UVk6vto4duldO lD26dPZ4XIPm5B2pqVsCBKSNkZcejqEUlZ/POERD7wjbO4YIZ5bbsH7Q6CChfnW4FlFg 7AnTgDx1LYJPCl3daCN5PtIAFF1veax8VAaFJcCAJJBcwE1tTj+BdCl2wci5lAhqwCBS fhBuEUAy4jCy9QMm4nf06HYgEO27ERL9uegbIYXBspLIHfezMcISCfnJhV/F3lrhPwDg Bfdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698359793; x=1698964593; 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=iLh8agMtrcsn72KEkgzj3KZJxRAWq8B9wJ+Ht1+nXGo=; b=Xht8QdHBeTepg4sqNHspyrHRh+uC1T04fXIgCCPRxDw/LRfeE2UVG0RU4xjNZbfhuf q3e6jygH7evcoFmGf8wQ37JvNzSVnjzNEwZZ1oLrP0/z3E7sAraxlHvGNPkBzi5k40UF B28dEwNWHxu6P8Wtki5m2ZejGazGrvn7aAWfD518us2O5muZ3XXH2nZM6NH6CqF4cO0k wvDfPv4h6LrWl+Ijkof8QSEgAWM5v8bd7JBoizExUzpvSt0Tn+f/YieB3bJe+Rt7rIok lqpxJpVYXSHOe3A/OOWMHWJKz4PGmbBEeiWJ41L/U47HLH05xJnpIDizawu6VNEqF9Ka p6YQ== X-Gm-Message-State: AOJu0YzKEmUUiOlUNH2wdKwJej9RGVE9Y1wuWxtm6XxQEdtwZN/Ph9N8 AguAX4bcoboYSvNPSHEHesN37+wIj8eVBrK1baULMqZp X-Google-Smtp-Source: AGHT+IGz4b6wvF5uDUwuaNodkYQ8+KOs9z6tpgn8ofi5LkN6quBJVgNHmgEVeUkcwGqrrnzAUSoJzvnq5egUkaTJ9LM= X-Received: by 2002:a05:6102:2a59:b0:457:ba42:eca2 with SMTP id gt25-20020a0561022a5900b00457ba42eca2mr937709vsb.0.1698359792534; Thu, 26 Oct 2023 15:36:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 26 Oct 2023 19:35:56 -0300 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000228b1b0608a63400" Subject: Re: [PHP-DEV] Basic Type Alias From: deleugyn@gmail.com (Deleu) --000000000000228b1b0608a63400 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Oct 26, 2023 at 4:23=E2=80=AFPM Larry Garfield wrote: > On Thu, Oct 26, 2023, at 6:37 AM, Oladoyinbo Vincent wrote: > > App-wide aliases run into the autoloading problem. If the engine runs > across the add() function above, and "numeric" isn't defined, what can it > do? Currently, all it can do is trigger autoloading, which only works fo= r > class-ish constructs (class, interface, trait, enum). Making type aliase= s > a full class-like construct seems... weird, and over-engineered. But if > not, how do we autoload them? And if they do autoload somehow, does that > mean we end up with a bunch of files with a single `type` line in them? > That seems not-good. You also then have to ask how they interact with > namespaces. > > So far no one seems to like my idea of "composer has a files block, PHP > has a preloader, they're small, so who the hell cares about autoloading, > just greedily load them and move on with life", even though I think that'= s > the best answer. :-) > > So any type alias proposal would need to sort out the above "definition > problem" in a way that's generally acceptable. That's been the hold up f= or > 3 years, I think. > > I'm also not sure why you're mentioning generics at all. Type aliases > would be helpful with generics, but they're also helpful without generics= . > They're orthogonal and not especially related. I agree that there's no > reason to wait for generics to add type aliases. > > --Larry Garfield > Unless someone else has good points to raise, it sounds like there's a clear sign that file-based type aliases are not useful for PHP. With that in mind, the discussion seems to point straight to autoloading. I think this shows a limitation with PHP Namespaces and Autoloading capabilities. I really don't want to judge/belittle/speak ill of something that was first released 14 years ago, which means discussion and planning had to have happened even earlier than that. Everything was completely different back then. What I see today is that PHP Namespaces seem to have succeeded thanks to Composer and PSR-4. Working without Composer in 2023 doesn't seem like a reality to me. Maybe I'm biased/young and if this premise is "too wrong" then everything else I say after this might be discarded. PHP Namespaces, Composer and PSR-4 can't really recreate the experience that ESM provides because 1) Namespaces itself aren't tied to file paths and 2) PHP doesn't have a build process (path aliases, Typescript types). What Composer and PSR-4 offers is a static build tool that runs once (composer dump-autoload) and creates namespace-to-folder mapping that can be used to discover symbols without a continuous build process or a continuous `composer dump-autoload --watch`. Now my question is: Why PHP Namespace limitation SHOULD be a deciding factor when talking about Type aliases? The problem is there and exists and is dealt with as best as it can by the union of PHP Namespaces + Composer + PSR-4. PHP already has a few symbols that require discovery: Class, Interface, Enum, Traits and they're all tied to autoloading in case they haven't been discovered yet. If a Type Alias triggers autoloading, developers are free to: 1- Implement Type Aliases using 1-file-per-type-alias (PSR-4 compatible). 2- Create a single type-to-rule-them-all.php and rely on Composer File autoload (greedy). 3- Write a custom autoloading function that deals with the problem however they want. 4- Manually `require_once` type-aliases files where they know they need to be used. 5- Not use Type Alias. To build up on my question, suppose someone one day comes up with a solution to PHP Namespace problems (that already affects interfaces, classes, enums and traits). Could Type Alias make it worse enough that such a hypothetical solution would be rendered impossible because Type Aliases were introduced in PHP? Does preventing PHP from having Type Aliases that comply with the current reality of the project benefit the project in any meaningful way that it will be easier for something in the future to be made better? I know it's hard to talk about hypothetical solutions when we don't know what they are, but I think we can ballpark that interfaces, classes, enums and traits are important enough that an enhancement to PHP Namespace system needs to bring enough benefit without a BC break to be voted in. And such improvement could just as easily take into consideration type aliases as one extra thing. Maybe my lack of knowledge on PHP Source code makes me think that Type Aliases aren't a big deal as they could be and some insight into that could shed some light into why this is too simplistic thinking. The simplistic thinking being: Take Namespaces as they were designed 15 years ago and add Type Aliases into the mix. Back then a solution decoupled from the filesystem was introduced and a userland autoloading function was the slim layer that made PHP Namespaces what they are. We can build on top of that mindset with type aliases. We need a syntax to declare them and an autoloading userland function to find where they are declared. Everything else can fall into place as it did before. I would love it if we could bring up a discussion on proposing changes to the PHP Namespace system to allow for something more like ESM while considering we don't have a build system and a hot-reload system, but I'm just not sure if PHP Type Aliases is where that discussion MUST to happen. If this line of thought has any merit, a better question would be whether Type Alias needs a separate autoload function from class/interfaces or a single autoload is better. I think that's the kind of discussion that would help Composer/PSR to decide how to expand and improve the PHP Ecosystem to include handling of Type Aliases. --=20 Marco Deleu --000000000000228b1b0608a63400--