Newsgroups: php.internals,php.internals Path: news.php.net Xref: news.php.net php.internals:121479 php.internals:121480 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12459 invoked from network); 27 Oct 2023 07:45:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Oct 2023 07:45:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E3D80180507 for ; Fri, 27 Oct 2023 00:45:32 -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-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.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, 27 Oct 2023 00:45:32 -0700 (PDT) Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-9c603e235d1so277606266b.3 for ; Fri, 27 Oct 2023 00:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698392731; x=1698997531; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=xAEvkDA6YU9mjipgb89uZX+pIgMD3SWK2tn6Rk69lDg=; b=IpbY7NEORFHi+739Lbyo3tNuzjDde+dtRx7r4WNvYxZbSGhM2ZtSrJuo4yu/nhTkSV oOLzR3HjqIGjHYDjY8PVQ8NfRIQFpaMToKBjVRvMVl9TusUs0APrdg6TTrjx2lz2s7uE TDyTKA5nOQw2CrhbyrVmYOZp3BeiiaSPHv76OBPX8xfzLUP/mjVXkSrIb44yOiz6+oiP 0oSkKblbGXMQeibTQzE0DIRSuwW37OATqeSz3Wv76a+zDG/TxH7+yaPTD7r5o57vNSrz DgxiLOOEwna+hJdbyOLAIUcvq73tDJX18uRjyD9oBh1JCJfCg0ByKI//B6dJSHT2q/dJ 9q3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698392731; x=1698997531; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xAEvkDA6YU9mjipgb89uZX+pIgMD3SWK2tn6Rk69lDg=; b=RxmYa1ryyCC4NpMatkVQb2IRwr5B3wr/5dpTPzQU6cPbwHfGcT+h4034denfGBBqje 9E5mXKPNPS5irMthyxdG9YXjYjfh2wfykMRbur1g1mJu9ENj5aqAYpv+PwnGTd5Eq1ga rH0J0smIHs5peRvAf+Dew2En2ovvDdtsLHuyLVO6ARHoYdnCUaGpSnTPrvWQsWt6SSIj H/thmuILSiA8+1lOa56I5KltFapzHyZCYkboAaDPGJl2upcjI+vE5ICHo/tLRnSQI47C LoIv2UZCaR2Bo6RwOspB3zVa5DCVL53K3LSrumx618hTRmZrR5fHfpMcl6mtxPubq43D 38Ig== X-Gm-Message-State: AOJu0Yznfthm471DHAnGdIuipbg1gHY+2g4iVyG9No+OilSzlWzbW4yk 3XjmMLhm6mc/Do6czmtt5NlPmaV6Bl0= X-Google-Smtp-Source: AGHT+IFQUQuqQa9YFFMSlAY9iXIMiyngPMnnYkAOvrh/T7pS7i+RL6sldgqygC9oJk1pVo6+NpYASA== X-Received: by 2002:a17:907:2910:b0:9c6:724:fa1f with SMTP id eq16-20020a170907291000b009c60724fa1fmr1166146ejc.66.1698392730419; Fri, 27 Oct 2023 00:45:30 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id k15-20020a170906680f00b0099b8234a9fesm781134ejr.1.2023.10.27.00.45.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Oct 2023 00:45:29 -0700 (PDT) Message-ID: <031056A8-8F22-439F-9B77-75929798D2DD@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_48773001-4E95-48E4-94D1-453DFA33D1BD" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Date: Fri, 27 Oct 2023 09:45:18 +0200 In-Reply-To: Cc: php internals To: Larry Garfield References: X-Mailer: Apple Mail (2.3731.700.6) Subject: Re: [PHP-DEV] Basic Type Alias From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_48773001-4E95-48E4-94D1-453DFA33D1BD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 26 oct. 2023 =C3=A0 21:23, Larry Garfield = a =C3=A9crit : >=20 > 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 for class-ish constructs (class, interface, trait, enum). Making = type aliases 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. >=20 > 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. :-) Hi, =E2=80=9CAutoloading=E2=80=9D does not mean (and has never meant) =E2=80=9C= one file per class-like construct=E2=80=9D; even if it is the most = customary strategy (and the one consecrated by PSR), it is by no means = the only one. Proof of concept: With the following autoloader, at the first time the = compiler needs the definition of some class-like symbol under the = FooBits\Acme\Type namespace, all symbols under that namespace are loaded = together: ```php spl_autoload_register(function ($class) { if (str_starts_with($class, 'FooBits\\Acme\\Type\\')) { // we have conventionally put all types defined by our library = under this namespace, // and there are all defined together in the following file: require 'vendor/foobits/acme/src/types.php'; } elseif (str_starts_with($class, 'FooBits\\Acme\\')) { // for other symbols we use the boring psr-4 convention require 'vendor/foobits/acme/src/' . str_replace('\\', '/', = substr($class, 13)) . '.php'; } }); ``` I think that treating the type aliases as class-like *names* for the = purpose of naming and autoloading (without giving my opinion whether = they are class-like *constructs* for some definition of =E2=80=9Care=E2=80= =9D) is a reasonable approach, and = autoloading/preloading/whatever-loading-strategy ought to be treated as = an orthogonal (non-)issue. =E2=80=94Claude= --Apple-Mail=_48773001-4E95-48E4-94D1-453DFA33D1BD--