Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119928 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99506 invoked from network); 11 Apr 2023 14:31:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Apr 2023 14:31:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 024E2180084 for ; Tue, 11 Apr 2023 07:31:55 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (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 ; Tue, 11 Apr 2023 07:31:54 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E1EF05C00CA for ; Tue, 11 Apr 2023 10:31:51 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Tue, 11 Apr 2023 10:31:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1681223511; x= 1681309911; bh=AihYPMPhFHv85FNCK2e7Svw0GmIG8fEh5MjccSRNyhU=; b=Q UCsM+7j0gyv5W5gNo427ab8ZI0GoMHJhMWyBEVtw8bzz7t9274ej06YcYAnOfYdb yJFNofzoM84KYMFR/kGfXNmXYUTTJFXBysHOjClWEvWmwiOidMxpDNnDQ3/rl/8o /MiIJ7TxD13+f7XnxM5eiGJ3n8RrrXBzieYqKI10b3ds9yDqU11z6mPYCOnlRI/h nhfVMv+hOfclIYGJafD9EQNAea4GOFVGG19mM009sRX633V7kydPDuPsQ7pX7ja+ Ar+R/iClWXNNI1/571qCLvRSYdbZtjd3AvqrTGBBGe2ODxkh8QJIymlANrV+8UpI XZHhGWNhpM57kBtSDnfQw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1681223511; x=1681309911; bh=AihYPMPhFHv85 FNCK2e7Svw0GmIG8fEh5MjccSRNyhU=; b=Z5X0Q+XI223PBt9wcYxIXs3jl2oLR ziOoBYL01CLQZ4sXri51YMOygxObhq5Q/TVnFjQb1EPNy8basZaqSsPtWfLV5Mwa kHlNA3nQF6iW3URDMKRoEnidrCpoWxdzOR7vJo9JGJ/P3dJkFmRf2WiUC1VS3m8A QOkS1jFOPLn/JW1zM7IX5ZunCEuh+YqedvbyAj6/Psl4tLXt7+CcgQvanwEd7s39 9PMnZwMWs+ax8TA3wjfYEMHernwLlbT29aTQbnoHFRoGeCE7PLCAdyED4321Uwh3 IHZV9TtF+WAdeb6o/CUt4ZnHh0MdDvcBSiYcVJiTsMTDeCQj8rWupXXtg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdekgedgjeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 85D191700090; Tue, 11 Apr 2023 10:31:51 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-334-g8c072af647-fm-20230330.001-g8c072af6 Mime-Version: 1.0 Message-ID: <8d390535-336f-4d29-9e3c-43b5e24213ee@app.fastmail.com> In-Reply-To: References: Date: Tue, 11 Apr 2023 14:31:29 +0000 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] PHP Modules From: larry@garfieldtech.com ("Larry Garfield") On Tue, Apr 11, 2023, at 1:40 AM, Michael Morris wrote: > This will be long. I've read over the Future Stability thread and taken it > in, and decided to mull over an idea I touched on over a decade ago that I > think might help. Also, in the interceding years the JavaScript community > has overcome a compatibility issue using this technique, so we might do the > same. > > The crux of the stability problem is the need to update functions without > introducing a BC break. Adding in new features without removing old ones > also makes it confusing to incoming programmers as to what to use. > > I propose PHP Modules to hold new features. The existing namespace and > functions would be left alone. Existing files would also not be affected - > the behavior of PHP modules would be entirely opt in. > > They would work similar JavaScript modules - they would use the import > keyword and the include, require, include_once and require_once directives > would pitch an error if used in a PHP module. PHP Modules also would not > parse as templates at all - no opening that will be a headache for IDE makers, but it's not insurmountable). > > PHP would have a new ini directive to use them similar to the "type": > "module" directive that npm uses now. If that ini directive isn't set, php > files would be handled as they always have. mphp files would always be > handled as php modules though and lphp (legacy php) would always be handled > as legacy php. > > I expect some objection to file extensions affecting parsing behavior, but > over the last 5 years this approach has worked for the JavaScript community > with cjs, mjs and js files. Here the existing php, phtml, php3, php4 > extensions are handled as the directive instructs them to be handled, only > the two new never before used extensions of lphp and mphp would do their > thing. > > In a PHP module a function has to be imported before it's used with a > handful of exceptions. The root namespace of php modules is utterly empty, > or as close to empty as makes sense. > > The existing functions would be gathered into modules so that they can be > imported. While this is done the headache inducing inconsistencies like > haystack, needle for strings and needle, haystack for arrays can be > addressed. I really don't care which is adopted, but having one order for > this language wide would be nice. Also, decide once and for all - camelCase > or underscore_case. > > The above alone would be massive. Maybe it's impossible given the number > of devs available. The one thing modules can do that the current system > cannot is allow devs to pick which version of the module to use: > > import split from 'php.mb' // imports the mbsplit() function from the > current version of PHP. > > Say the mb module gets some bc breaks. We can put them into a new module so > that the behavior is once again opt in. The strongest way to do this is to > make composer a 1st class part of the language and let it specify the > version of the module that is loaded. > > The import command would be able to pull from the file system or from the > import map as JavaScript does currently. For ease of dev headaches I'd > recommend hewing to the JS model as close as possible as it is proven, and > many of us already use it anyway when developing browser code. > > I hope this helps, or at least spurs a conversation to come up with > something to address this issue. The main question, in my mind, is what problem is this solving. From the description here, it sounds like you're targeting "clean up inconsistencies in the stdlib", which could be done much more easily by putting new versions in a namespace, something that's been discussed many times. (And usually run into a wall of how much redesigning we should do in the process, and then people lose interest.) The previous times modules have been proposed, the big selling point was module-level visibility. Eg, object properties or methods that are visible to other classes/functions in the same module, but not outside of it. That's a problem space that would be solved by modules, which namespaces cannot solve. (Whether worth the effort or not is a separate question.) Most of the BC discussion right now (and generally) isn't about function or class redesign. It's about changes in language syntax behavior, such as undefined-var/key being promoted from Notice to Warning (8.0), or making dynamic properties opt-in via an attribute, or having stdlib functions react to null parameters the same way as userspace functions, etc. Regardless of whether you consider those good or bad changes, they're not the sort of thing that modules would solve. There has been discussion in the past of adding more declare statements to allow opt in/out of certain changes, like declare(warn_on_missing_var=1) or something. To whatever extent that's feasible, it's less work than doing it that way (per-file) than introducing a module system to handle that switch. However, as previous discussions have shown that is also a huge amount of work, as we have to maintain two different behaviors in the engine and switch per file... and then also figure out when the default changes, and when it becomes just the new approach always. Which doesn't solve the issue that at some point code that ignores missing variables *will still break*, it's just pushing that date off even longer at the cost of still more engine complexity. But the same people will still complain just as loudly whenever that is, because they haven't done anything about it for the past 17 years so they're not going to now. So, what are the problems to be solved that only a good module system would be able to? Start there, before thinking about how a module system would look. I do think there are potential benefits to a formal module/package system, but that's where the discussion would need to start, not with what the