Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124302 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 9BE621A009C for ; Tue, 9 Jul 2024 03:25:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1720495589; bh=LAILrcOW08agnxPfbIyKNI9X2/6/kMDD1gmLjLLFRhs=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=ROeFHu2d+1pqE44DurwLmdoWEM9KjaqJQosxyabKfhtILrYX5SPsWy7OdWCw9kfth qSVcpTm8+IEakCliXMhUcp0z4HZ1NxBVjEf4LwrBIToPdh5E//9pJ8q6xIqQw6M+fa jGnjppmBW9AldBY3oTcf7zmdqpOiasHAMRusylekHimyhG0FLxfkSnPLp3Lr+Xq+1L 5rSYWaPtwJ5QsEMNaIaT6nabyLn/QjBtkCJSyqJrxdU1gtq39ENr6sMOdKuN6N66J4 cG+joHhZ3khCi87ZVLSJjZKaE1RfRqQ35lvMZlGQ1sG1oJE9tfjJL0iV0aRyuNnOce ydkr15og5cwzA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5A106180083 for ; Tue, 9 Jul 2024 03:26:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 9 Jul 2024 03:26:27 +0000 (UTC) Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e036d1ce4f7so3197965276.0 for ; Mon, 08 Jul 2024 20:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1720495502; x=1721100302; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mK/2rzhSX6Up/LkyrtYOadP99/6qx2E4cuRO6eixdTM=; b=u+ioKb8uaU8saG2skmd+dPFwhJzjxomySEUxUsgmp5UdiQWlkWbl0bsTJcoOedeDT6 YDkRq1dmoinlflZejzabPxIN7RSQ/xvb+R/D+VfryUNLx5+vih9TrHaAAH0nbABRUWV8 gjgVmE30xo0oiNIPfVNNx/ngYEoaZqf6bLRE7lkWqfDp0/oKNP4YcrJaSfL2rXJhWLjs f3yNLKkv7LVoGGGfMfCmRo+xJmM1tk5otcTMrOry0AMjOorwLpm2US/pBgpTsOIaoPSe qbhjnd3LjRFO6Z+vWCxlx3LxtlgNSbgSdpUvX+bUYds37lnY7oHQh7BDvCWwBARKFwr3 Bx9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720495502; x=1721100302; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mK/2rzhSX6Up/LkyrtYOadP99/6qx2E4cuRO6eixdTM=; b=JRcF3qIbwxB8+d5Cm0CmiXNLToiyukVujP5MIMm06jLkWW/uy4n2rPeAqPgqnlOmKJ 3QYDEfQq1z4QXGbDk/l9POT2Z4Ol5R7nJAZT16SfZWfRv0QgbztgZF1c5NuR/o3eGetH styKBfz8HfbPI9/OWlh8kRNJaPZNcQVB+G9S8qeVfoM6clV3IQPjyDQ7PQB4TtFKRFgV OI+NJORu3PLeUMZLGC6rCLvgxvAeB92CMytnWWNRbm25Vwk0YE0c+oEgoQqSJ4/C0Odu Mbv2gL+HaHV/Rf5hQd4k8Kxp6ha/cM4JE6zsIarSJCA9meoLGS3/kpZ5uPDiDE6t//cB iWbQ== X-Gm-Message-State: AOJu0YxrYBS3pHCuuic33a4QimcBYAs0dYqSJ8TyxxY+OtxhqCgoH+Cj uBTfcgYPAJUN0rMoMjupyyhgn6xt9dF1Q0BRH6ezhI3vmRtVHOQaKJoB3SOQU8nLSp66CkdiPbl ioec= X-Google-Smtp-Source: AGHT+IEhOUpLrCJCpp4KL/oD8EBNwdPlV1yDmGSNHI68Zs/HTEYbbkn2WHVVLqxDf78l+Eh6uxnSPA== X-Received: by 2002:a25:660b:0:b0:e03:9d95:e239 with SMTP id 3f1490d57ef6-e041d1ad42cmr780122276.14.1720495501806; Mon, 08 Jul 2024 20:25:01 -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 00721157ae682-658e49360f0sm2180597b3.9.2024.07.08.20.24.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jul 2024 20:25:00 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: [PHP-DEV] [PHP-Dev] Versioned Packagers (Iteration IV) In-Reply-To: <1BE6A849-A2A9-4E17-9C11-5099EF74F5C0@rwec.co.uk> Date: Mon, 8 Jul 2024 23:24:59 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <09559430-4477-4516-8D78-6F4071E1AA6C@newclarity.net> <0182F3D6-F464-477F-9029-A2D0A8B50C71@koalephant.com> <1AFD7AAE-8BEA-460D-88A8-15BB3D30A775@koalephant.com> <1BE6A849-A2A9-4E17-9C11-5099EF74F5C0@rwec.co.uk> To: "Rowan Tommins [IMSoP]" X-Mailer: Apple Mail (2.3696.120.41.1.8) From: mike@newclarity.net (Mike Schinkel) > On Jul 8, 2024, at 5:41 AM, Rowan Tommins [IMSoP] = wrote: > I agree. I wrote most of the below a couple of days ago, but I don't = think it posted correctly, so apologies if some people see it twice:=20 >=20 > Autoloading is just a way to load files later, by the engine telling = you when a class is first needed. PHP does not, and should not, make any = assumptions about how files are laid out on disk; an autoloader doesn't = actually need to load any files at all, and if it does, it uses the same = include or require statements which have been in PHP for decades. I think maybe you are replying to an earlier iteration by Michael Morris = and have not seen the more recent iteration? =20 There he explored adding an additional function to named = `spl_autoload_map()` where the difference from `spl_autoload_register()` = is that while the latter uses procedural code to determine what should = be loaded the former would use a declarative map to determine what = should be loaded. Then Composer and/or other tools could/would generate = that map for PHP. With an `spl_autoload_map()` PHP would not need to make any assumptions = about how files are laid out on disk. Instead, PHP would use a schema of = a yet-to-be-determined data representation format to discover = declaratively where files needed to be laid out on disk. > Likewise, installing packages and defining version schemes is a = completely separate problem space that can probably be served by a few = small tweaks to Composer once the language provides the underlying = functionality. >=20 > The core of the problem you seem to want to solve is this: if you have = two files foo_1.php and foo_2.php, which both define a class \Acme\Foo, = how do you load both of them, so that you end up with two differently = named classes?=20 That is one (1) of the core problems, yes. > In JS, that's easy, because functions and object constructors (and = "classes") exist as objects you can pass around as variables, they don't = need to know their own name. In PHP, everything is based on the idea = that functions and classes are identified by name. You can rewrite the = name in the class declaration, and in direct references to it, but what = about code using ::class, or constructing a name and using "new $name", = and so on? How will tools using static analysis or reflection handle the = renaming - e.g. how does DI autowiring work if names are in some sense = dynamic? This is one of the unfortunate aspects of PHP never makes types a = first-class data type. But I digress. > You've also got to work out what to do with transitive dependencies - = if I "import 'foo_1.php' as MyFoo", but Foo in turn has "import = 'guzzle_2.php' as MyGuzzle", what namespace do all Guzzle's classes get = rewritten into? What about dependencies that are specifically intended = to bridge between packages, like PSR-7 RequestInterface? Which is a direct result of the other problem you mentioned, i.e. IOW = without attempting to address the prior problem this would not be a = problem. #fwiw > My advice: start with the assumption that something has already = installed all the files you need into an arbitrary directory structure, = and something is going to generate a bunch of statements to load them. And this sentence is why I chose to reply to your message. That = assumption itself blocks the needs of user-managed apps. (Did you happen to read my compare-and-contrast of user-managed vs. = developer-managed apps from a few days ago?) I feel it is likely those who have never worked professionally in PHP on = user-managed apps like WordPress =E2=80=94 which I assume describes you = accurately? =E2=80=94 are probably just simply unaware of the problems = that your assumptions cause for user-managed apps. And yes, some = developers have no empathy for others who have different circumstances, = but I honestly don't think you (Rowan) are in the category.=20 Developer-managed apps use a build tool to put all vendor code in a = single hierarchical set of namespaces and then load needed code from = there. But that really does not work for user-managed apps like = WordPress or Drupal. Or at least not as they exist today, and probably = not even if they were rearchitected for the start. What works for user-managed apps is that each `add-on` (`plugin` in = WordPress, `module` in Drupal) is stored in its own self-contained = directory containing its own vendor code =E2=80=94 where some of the = vendor code could easily be duplicated in another add-on =E2=80=94 and = then the user-managed apps itself manages loading of all add-ons itself = without a PSR-4 autoloader. As it exists, there are no standard for how = add-on filenames and directory structures much be named nor how they are = to load their dependencies so it is impossible for WordPress or Drupal = to take on that role using PSR-4 for them.=20 Michael Morris' idea to add an `spl_autoload_map()` function would allow = addressing the needs of user-managed apps that treat each add-on as a = self-contained entity. But making the assumption that "something has = already installed all the files you need into an arbitrary directory = structure" is not sufficient for the problems Michael Morris and I have = been trying to address. An autoloader map schema that has enough information for PHP to = understand how to manage the conflicting names, and for the user-managed = apps and Composer to be able to tell PHP what names are conflicting is = in fact a solid way forward. -Mike