Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121484 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36059 invoked from network); 27 Oct 2023 10:25:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Oct 2023 10:25:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 588741804D0 for ; Fri, 27 Oct 2023 03:25:29 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE,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-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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 03:25:28 -0700 (PDT) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-5a7ac4c3666so13933427b3.3 for ; Fri, 27 Oct 2023 03:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1698402328; x=1699007128; 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=PYCdxMZkzQC1wRqa9ir1MsE+3h81vmKNDJhhy0rEmF4=; b=K79aRMpi3zF1qsOVoENXlml9dZnWBCC7VRhqkQf9rTLLO2DZVG2kVB7162MTtNPEQP n+Tqb7jXFdUbOX954IObtkhHhfaNl5sGqd95MXa3aV44CUEoFkStI4mypH+PqcZGMgUY kkpaRHelrBEZfl6n+6oNtytQwja/2IXRG3G3NaDEpASQMmkmq++SBxTk/gH4P9MVUKrR gh9tFi/r/aHWVgI8nbXIx25EtmblWLV6saRwCwubRtNtZEgzocN0xrPbAvV/1KQq1X4x KFdx6bzPFvqdPgPaQ3fDRkybz+RW97bFFQHq3HNbarELU4dngnotgo+3KXB0oOk/2ACv YhEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698402328; x=1699007128; 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=PYCdxMZkzQC1wRqa9ir1MsE+3h81vmKNDJhhy0rEmF4=; b=hs7GRfeXcJZmNehBHMsWKsaM35gQ2eFu6BTY/WbIcIAiocJLOs7JT4xrtM06Nqs9nt PZ6CEpIydoWjoeAgRtarLIwPuJAj9xg1J6cZBH/CxAEG86vdKaCoM9+IwbxngAe5zjSL PER+daA2vtsYY5voCQNQzWs97nXqes+//Bjp/PyVhG/LlyUrLNAzR3/1lFfA3u+nYYMk Mb7I7EbvArq+b7kqmoAyEBJklfYZ9HwimdF4XyRFvDlUUCCR+1ov77V+vtmzRusbi+F6 CyACPtblVl7L7KCT6SetWgx+yJ2iMbc6N/npZ4uua98SovVOE0alaqohjhDkYAGGGVCK y/Og== X-Gm-Message-State: AOJu0Yyxno6WUSMkcqSpRZMMgGZxl103EtdZz0KBRuDkUg/+ZdIv0pzi V0Y+qQVJtEXa3j0ZoHLKTzXlOcoubmijvumUmdml7g== X-Google-Smtp-Source: AGHT+IG/p/GxJpmTC6EzaqBQt7EZD18gl4KlLKgmS/uWP+jBCAlXsHp00ug87iQpfH6K3G9nhwnV2w== X-Received: by 2002:a81:bc45:0:b0:595:e1b:b978 with SMTP id b5-20020a81bc45000000b005950e1bb978mr2451915ywl.21.1698402327804; Fri, 27 Oct 2023 03:25:27 -0700 (PDT) Received: from smtpclient.apple (c-98-252-216-111.hsd1.ga.comcast.net. [98.252.216.111]) by smtp.gmail.com with ESMTPSA id q72-20020a81994b000000b005a7cc149e3asm585055ywg.2.2023.10.27.03.25.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Oct 2023 03:25:26 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_D0F42473-3041-4198-A53F-14BBF92787A1" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.4\)) Date: Fri, 27 Oct 2023 06:25:25 -0400 In-Reply-To: Cc: php internals To: Larry Garfield References: X-Mailer: Apple Mail (2.3696.120.41.1.4) Subject: Re: [PHP-DEV] Basic Type Alias From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_D0F42473-3041-4198-A53F-14BBF92787A1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Oct 26, 2023, at 3:23 PM, Larry Garfield = wrote: >=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. =20 Curious, how do you define a "full class-like construct" in this = context? Anything more than autoloading? =20 And would autoloading actually require something to be a "full = class-like construct," or could it not be something lighter weight = (assuming full class-like constructs are not than just autoloading?) > 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. Straw man proposal: When PHP recognizes a symbol in the context it would expect a type yet = PHP does not recognize that type, PHP could use the existing autoload = mechanism to determine files and directories in which those types might = be located. This would address namespaces, I believe Then, following PSR 4 is could attempt to autoload via a file of the = same name. If there are types and classes, interfaces, traits and/or = enums with that same name they would all need to be contained in that = same named file, much as it currently works.=20 Of course that would require one .PHP file per type which as you mention = would not be ideal. So instead, a new PSR could be created to extend PSR 4 to add = type-specific considerations. For example, when the type passed in is = "Foo" it could first look for `/~types.php` and load it but it that did = not work then it could look for `/~types/Foo.php`. I picked the tilde = (~) since it cannot be part of a valid namespace of class name so no = backward compatibility concerns. If the type name passed to the autoloader is `Foo/Bar` then it could = look in `/~types.php` first, if not there then `/Foo/~types.php` and if = not there, then `/~types/Foo/Bar.php`. I picked the tilde (~) since it = cannot be part of a valid namespace of class name so no backward = compatibility concerns. Having a single `~types.php` per namespace would let developers put all = their types for that namespace there, if that is what they prefer. Or = they could pull all types in the root's `/~types.php`. Or they could = create a file for each, whichever their preferences. I am envisioning a new `type_exists()` function would be required. Even better would be to add an additional optional parameter $type to = my_custom_autoloader_new() which could either pass in a numeric for some = new predefined constants like PHP_AUTOLOAD_CLASS=3D1, = PHP_AUTOLOAD_INTERFACE=3D2, etc., or just a string like "class", = "interface", etc. Based on that idea, such an autoloader might look like this: function my_custom_autoloader_new( $name, $type ) { $dir =3D __DIR__ . '/includes'; switch ($type) { case PHP_AUTOLOAD_TYPE: $file =3D sprintf("%s/~types.php", $dir); if ( file_exists( $file ) ) { require_once $file; } if (type_exists($name)) { return; } $file =3D sprintf( "%s/~types/%s.php", $dir, $name ); default: $file =3D sprintf("%s/%s.php", $dir, $name); } if ( file_exists( $file ) ) { require_once $file; } } =20 > 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 for 3 years, I think. The above is potentially one way to skin that cat. =20 Anyway, I'm sure there will be lots of opinions on this, so bikeshed = away. -Mike --Apple-Mail=_D0F42473-3041-4198-A53F-14BBF92787A1--