Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127523 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 lists.php.net (Postfix) with ESMTPS id 2C19C1A00BC for ; Sun, 1 Jun 2025 16:05:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748793830; bh=Bz2s9vf1s9/E9Qqn9Lbifo61E4esCCiB6h2EUzy7Xqg=; h=Date:From:To:In-Reply-To:References:Subject:From; b=GKY1xCvW5YuGuft+r95gIDDOkhTCzHmOVX58fijynvAYg8gD6pxwUS0DXSVwGetrk al+BakqRsHjY6dCBbzEmeqWMQGlfLhlteL5/Z7IL3WiJWCtUHnrPPfWg+FwaKi4hcJ GEYV6eVccHLImnMEZhPyYTxwSepp/HLeENtvfH4PoiE1uky4Dg3U5EThjtJg6eID1R lzCuuGBiSjQYxeB27iqOPZO2JCZh91zqqg1BZj/nNaGC2wl7FRuuo1ZdG/lwocAfWi D+MIoBRPfNElQtAdQTXsXhqoWkBOtCwABuB9Zr/0ubRv7zs2+K0NVCCGzvzVHP0dN5 MgQ2x8bEZXVuw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 34DAA18002F for ; Sun, 1 Jun 2025 16:03:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) (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 ; Sun, 1 Jun 2025 16:03:48 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.stl.internal (Postfix) with ESMTP id 486EF25400A7 for ; Sun, 1 Jun 2025 12:05:53 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Sun, 01 Jun 2025 12:05:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm1; t=1748793953; x=1748880353; bh=d9+Va6Z4KlyykAt9JV1Wp x8ZjzkkmPx9ZBY8MnGzhFU=; b=hiLb5TeFXtUoI7xQgIF5a7CuJ3rTzz5NhDmDV 591Wy3BsAPABiFOck+aF3T7y1NCb/3RiSJu1EWZMEBfr3iZoIhs9MOMO4kmNcXVN JNnTH6ahp1Q8UTMNgalWpfG/rUtWTQuV26zJshqZPEDucnntrSC4ILUtQzrbfYh2 BSK8YypBAjVJGDxW8Dq5aNvbdx2QS0IhcL3YawCgYQNAkAV0VltqK+Uybq+x7R21 MWST+GtW4eC/O78JX7U/jCfsqLJzAc38VdT0PYqPjzOHxWHipPOiWRcp3JQgpzb7 h6Es5PmBkXtZ+fAF8wrU/hWY1+e849wWo22Zb38fBKqB3QLtA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1748793953; x=1748880353; bh=d 9+Va6Z4KlyykAt9JV1Wpx8ZjzkkmPx9ZBY8MnGzhFU=; b=LIJF0g9pyLGMaKp7P e+uVuoAAf8heVstCmjNtppydy5LVimc0q9sFHlrZrZA1msb9fILnW+EPDv1H4aSK 9KHdDRPM8zDHATCUBYzeG8HHNVQq1UhTiRKSPEuylGXvrtyaqhNMxqp0OcYUdg1/ f69aMQldDe5dy/05TVwyRSqlYrqWgOSpJZtmyuGon2WDYwuxXNIdTFuIkFRo6u9P DjBz6G55Jb2hdChflhCf+tTpQCGg2tWJmAJS7WPKpqlZxm66ZbVdHpheUcd8uRVL jno4rRZIh8KRzOqRVE8iT+QXcgJDANqY8H0APX8QSID1kzbbxM8/4UqxvJbz67Tw /WC/A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdefhedvfeculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefoggffhffvkfgj fhfutgfgsehtjeertdertddtnecuhfhrohhmpedfnfgrrhhrhicuifgrrhhfihgvlhgufd cuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqnecuggftrfgrthhtvghr nhepudegvdelgfeugeehfeejteffudevleethfefgeejffffleegtddtveekgeekudfgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhr hiesghgrrhhfihgvlhguthgvtghhrdgtohhmpdhnsggprhgtphhtthhopedupdhmohguvg epshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhp rdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id B6972700060; Sun, 1 Jun 2025 12:05:52 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: Te4ea9ce7af33d8fb Date: Sun, 01 Jun 2025 11:05:32 -0500 To: "php internals" Message-ID: In-Reply-To: References: <78641D8B-AF1D-4912-920A-D75A37C32F05@rwec.co.uk> <354cb888-97c4-4f8c-a0da-359d1e63c0f9@rwec.co.uk> <10D95B6E-094B-4EAE-A18A-AF6B795CB352@rwec.co.uk> <2adbff61-5e11-4d39-ab5c-d7950a4550a6@app.fastmail.com> <79E7FA26-2F5A-470C-B1DF-12CC46A08FE5@rwec.co.uk> <1c6dcd84-9016-48e1-971f-de7749cbdce8@rwec.co.uk> <44F59416-3922-4AF4-881A-C64F2C4E9345@rwec.co.uk> <7F11844A-A98C-4843-BC94-815FBCD2B73F@garsi.de> <7840468C-F60C-4A44-AE40-16F9007EF428@rwec.co.uk> <160E9B1D-9AF6-479B-A628-A73C618D7C1B@garsi.de> Subject: Re: [PHP-DEV] Module or Class Visibility, Season 2 Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Sun, Jun 1, 2025, at 12:26 AM, Michael Morris wrote: > $myModule = require_module('file/path'); > > or perhaps > > const myModule = require_module('file/path'); > > The module probably should return a static class or class instance, but > it could return a closure. In JavaScript the dynamic import() > statement returns a module object that is most similar to PHP's static > classes, with each export being a member or method of the module object. > > Circling back to a question I know will be asked - what about > autoloaders? To which I answer, what about them? If the module wants > to use an autoloader it has to require one just as the initial php file > that required it had to have done at some point. The container module > is for all intents and purposes its own php process that returns some > interface to allow it to talk to the process that spawned it. > > Will this work? I think yes. Will it be efficient? Hell no. Can it be > optimized somehow? I don't know. I think there's a key assumption here still that is at the root of much of the disagreement in this thread. Given that code from multiple files is clustered together into a "thing" and Given we can use that "thing" to define a boundary for: * name resolution (what Michael is after); * visibility (what I am after); * more efficient optimizations (what Arnaud showed is possible); * various other things Then the key question is: Who defines that boundary? Is it the code *author* that defines that boundary? Or is it the code *consumer*? Similarly, is it the code author or consumer that has to Do Work(tm) in order to leverage the desired capability? Or both? This is an abstract question that I think needs to be resolved before we go any further. There are certainly ways to do it with either party in control of the boundary, but I suspect many of them will be mutually-exclusive, so deciding which tradeoffs we want and what future features we're OK with blocking is highly important. My own take: The boundary *must* be definable by the author. The author knows the code better than the consumer. The odds of the author botching the boundary and making subtle bugs is orders of magnitude less than the consumer of the code botching the boundary. (Eg, if a class is declared module-private, but it's the consumer that defines what module it is in, then access to that class is completely out of the control of the author and it's really easy for some code to break.) Potentially we could allow the consumer to decide how they want to leverage that boundary (either by just using the code as is normally now, or wrapping it into a name resolution container), but the boundary itself needs to be author-defined, not consumer defined, or things will break. I realize that makes it less useful for the goal of "support old and unmaintained WordPress plugins that haven't been updated in 3 years" (as it will be about 15 years before WP plugins that have bothered to make modules/containers/boundaries get abandoned), but my priority is the consistency and reliability of the language mroeso than supporting negligent maintainers. One possible idea: Starting from the proposal Arnaud and I made earlier (see earlier posts), have a Module.php file rather than module.ini, which defines a class that specifies the files to include/exclude etc. Then in addition to the "just use as it is" usage pattern we described, the consumer could also run something like: $container = require_modules(['foo/Module.php', 'bar/Module.php'], containerize: true); Which would give back an object/class/thing through which all the code that was just loaded is accessed, creating a separate loading space that is build along the boundaries established by the module/package authors already. (Note: This still relies on all of those packages being modularized by their authors, but again, I think that is a requirement.) --Larry Garfield