Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123963 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 D60771A009C for ; Thu, 27 Jun 2024 20:54:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719521756; bh=z6sTM5Yw/G7AJ7x77nTRR9gGQ/XC0nux4pUu/GXpJ88=; h=In-Reply-To:References:Date:From:To:Subject:From; b=dNY+mz3rUL+PyxuZyfdAqxFJm0vYkkCgpyuM5adQ8VXmtfYFbESHkPhtwqe2LjEju Lhhk+JdrnvmJ4Sr23FRNq6o2ojjwlVhWWb9W3obE05Nhf4RyVEwp5qNmc5cdvhC3vA lDL5C/DZ0xEtF/LTR6uwaDJqsBS8buXM5dT3Jd5Azbwd82S0Hs9uk7gWXmkaihWe/T +5JP8CRyvG8fpFpTSEIBBGNaA1uqyzcYntp57hZzW6GcfXmkji/W/Lxwaf77lZ90RM kwl4Nzrb6sHBXGrfoobcJcuGl1tX0o+PrwIrULYh+2grqRGyBhHHTg36CgxnlHV80s PcFUKo3XUIpjA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9401A180A7C for ; Thu, 27 Jun 2024 20:55:55 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,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 wfhigh8-smtp.messagingengine.com (wfhigh8-smtp.messagingengine.com [64.147.123.159]) (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 ; Thu, 27 Jun 2024 20:55:54 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 4AC1C1800107 for ; Thu, 27 Jun 2024 16:54:35 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Thu, 27 Jun 2024 16:54:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=fm3; t=1719521674; x=1719608074; bh=riZweDmLQ/ 0dI7CXm54QV2xsbjHLKft14ezInZjYoDA=; b=B8TW6jqr3ZdQeAbUkUWhdIbCBr 6gVgSfm7DzXcWfT3RdEgwOADjb/k6BGV40Z0zX+TDaAo1xLLFVXdyPG91fbi9t4W IoM17H4DnOPtDaq/gQFoTQ6A0ml0mLcXJN6XSeUgq/gflygg25n3gSZetxuRlkCu gFhtcHgYN/0yR65qpCJB1NYNRi8paPSxJPVKmiAlBaPUobBmGuzKj/CbnlRkY1f/ KUMmI4LcRvW3lMXOAYjMbHEDvfUpMak0bIGIwgy3f7awp62+9UgmDcdUwPy17Woz ZiKpILWKtWvFyHGwHCl981+OQa+urt03CTZtn9FQWZ0tzA+eVZrKio6cRWdw== 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:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719521674; x=1719608074; bh=riZweDmLQ/0dI7CXm54QV2xsbjHL Kft14ezInZjYoDA=; b=g8lN0sD5DKEvosd/mB28ve000pKfhomCQFyW+nNuQ7yV waE26OhALNdDM593EBSTixhYXRPJXZnw7UcqlTYfHmlrC2s2CftOkqy3HSXiptyo YAcven2HAjYiIynrA0oTbOydtBZnUlPqLknWjU7NS6nEjLQLbhmh0BjMj0vhmo3H x8FJ25cOzTN9jpnGeGOUuBg1aSGUOdFY8DEA7oeQ/Hjqi+Vx1qMNw7lu+HXTo3ko jo+Sr6W67UV+DoSMYzENsalWrDNC8+qXBKRZZ7B5hEuHDQ9uf8kn7PachUgyIqDe QNJuK+K3N3WUvMK7L1guw1p14vOjpJnMbysyqnjD4Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtdeggdduheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsegrtd erreerreejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothht lhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepfeefudfhudduieekkedugffhud fgleejgfekgefhvdeikeelvddvjeehteegteegnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvsh X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 863AA15A0092; Thu, 27 Jun 2024 16:54:34 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-538-g1508afaa2-fm-20240616.001-g1508afaa Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <103583ca-2d74-4ddd-a9a4-88ea5d968b5d@app.fastmail.com> In-Reply-To: References: Date: Thu, 27 Jun 2024 22:54:13 +0200 To: internals@lists.php.net Subject: Re: Fwd: [PHP-DEV] [Initial Feedback] PHP User Modules - An Adaptation of ES6 from JavaScript Content-Type: multipart/alternative; boundary=90048e65cc0e4158bf652b6f0f6902eb From: rob@bottled.codes ("Rob Landers") --90048e65cc0e4158bf652b6f0f6902eb Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Jun 27, 2024, at 21:23, Michael Morris wrote: >=20 > On Thu, Jun 27, 2024 at 1:02=E2=80=AFPM MKS Archive wrote: >>>=20 >> Interesting to see this. Serendipitous given the email I sent on the = list in reply to Larry. >>=20 >> My initial thoughts: >>=20 >> 1. I really like the concept of cleaning up issues that BC make impos= sible to fix by introducing modules. >=20 > Thanks. The sticking point is what degree of change should be occurrin= g. PHP isn't as behind an 8-ball as JavaScript is since the dev can choo= se their PHP version and hence deprecation works most of the time for ge= tting rid of old stuff. But not always. Changes that are incompatible wi= th what came before need a way to do things the old way during transitio= n. Again, see PHP 6 and unicode, which snowballed until it was clear tha= t even if PHP 6 had been completed it wouldn't be able to run most PHP 5= code. It=E2=80=99s not just up to the dev, but the libraries we use and whethe= r or not we can easily upgrade (or remove) them to upgrade the php versi= on. > =20 >> 2. No need for autoloaders with modules; I assume this would be obvio= us, right? >>=20 >=20 > Depends largely on whether modules can include and require to get acce= ss to old code. I also didn't discuss how they behave - do they share th= eir variables with includes and requires? I think it would be a mistake to exclude old code and/or prevent templat= ing. Not only are there now decades old code in some orgs, but how would= you write an email sender that sent templated emails, provide html, gen= erate code, etc? There has to be an output from the code to be useful.=20 > =20 >>=20 >> 3. Not a good idea to use an ini setting; most view them to be proble= matic. >> 4. .htaccess =C3=AEs Apache-only, so a non-starter anyway. >> 5. The first script should not be a module. If you want that, have a = 1 line index.php file do an import. >=20 > I love this idea.=20 >=20 > =20 >>=20 >> 6. Modules should be directories, not .php files. Having each file be= a module makes code org really hard. >=20 > Yes, but that is how JavaScript currently handles things. It is curren= tly necessary when making large packages to have an index.js that export= s out the public members of the module. This entry point is configurable= through the package.json of the module. I think it=E2=80=99s fine to use js as an inspiration, but it isn=E2=80=99= t the only one out there. There is some precedent to consider directorie= s as modules (go calls them =E2=80=9Cpackages=E2=80=9D) and especially i= n PHP where namespaces (due to PSR-4 autoloading) typically match direct= ory structures. For example, I=E2=80=99m still going to go forward with my #[Internal] a= ttribute RFC some time in the next month or so, which will be namespace = based. I have no idea if it will pass, (some people are worried about it= clashing with an RFC like this one) but I think we=E2=80=99d have value= in it for years to come until something like this gets fleshed out. We = will see=E2=80=A6=20 > =20 >> 7. Modules would have a symbol table metadata file generated by IDEs = and during deployment. >=20 > Node.js uses package.json and the attendant npm to do this sort of pre= p work. And it's a critical part of this since modules can be versioned= , and different modules may need to run different specific versions of o= ther modules. Please, please, please do not make a json file a configuration language.= You can=E2=80=99t comment in them, you can=E2=80=99t handle =E2=80=9Cif= php version <9, load this, or if this extension is installed, use this.= =E2=80=9D Maybe that is desirable, but doing things slightly different based on ex= tensions loaded is def a thing.=20 > =20 >> 8. If no metadata file in directory PHP can generate one in memory du= ring first directory access.=20 >> 9. .php files in modules as identified by metadata file should not be= loadable via HTTP(S).=20 >=20 > Those are implementation details a little further down the road than w= e're ready for, I think.=20 Personally, if these are going to have any special syntax, we probably s= houldn=E2=80=99t call them .php files. Maybe .phm? > =20 >>=20 >> 10. Having exports separate from functions and classes seems like it = would be problematic. >=20 > Again, this is how they work in JavaScript. Not saying that's the best= approach, but even if problematic it's a solved problem. the only thing I don=E2=80=99t like about this import/export thing is th= at it reminds me of the days when we had to carefully order our require_= once directives to make sure files were loaded before they were used. So= , I think it is worth thinking about how loading will work and whether l= oading can be dynamic, hoisted out of function calls (like js), how orde= r matters, whether packages can enrich other packages (like doctrine pac= kages) and if so, how much they can gain access to internal state, etc. = This is very much not =E2=80=9Ca solved problem.=E2=80=9D > =20 >> 11. Exports could be implemented as attributes, which could be really= elegant. >> 12. Exports as attributes pairs with the symbol on the line above, an= d would enable easy aliasing. >=20 > Ultimately everything in JavaScript is an object. JavaScript provides = a mechanism for handling a module file with a single default export, but= it supports multiple exports from the same file which arrive as an obje= ct best approximated in PHP as a static class. I could hash out further,= but again, I'd like to gauge some interest and very high level feedback= . I'm also interested in learning on how other module systems out there = do work. I'm picking of JavaScript because most of the PHP community has= to use it as well for client side scripting and so most of us should ha= ve at least passing familiarity with it. In JavaScript, arrays are instances, in php, they are values. This is so= mething to consider if a module exports an array of exports.=20 > =20 >>=20 >> 13. And finally, when are you starting the RFC? :-) >=20 > It's too early for anyone to start at this moment - and while I certai= nly am willing to help I'm not qualified to take the lead on this. > =20 > If adopted, this is a massive change, and the results of this conversa= tion won't hit for years. Let's take our time. For one, this overarching= project will need multiple coordinated RFC's, as well as figuring out w= hat to do and also in what order. =E2=80=94 Rob --90048e65cc0e4158bf652b6f0f6902eb Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Thu, Jun 27,= 2024, at 21:23, Michael Morris wrote:

=
On Thu, Jun 27, 2024 at 1:02=E2= =80=AFPM MKS Archive <mikeschinkel@gmail.com> wrote:

Interesti= ng to see this. Serendipitous given the email I sent on the list in repl= y to Larry.

My initial thoughts:
<= div>
1. I really like the concept of cleaning up issues th= at BC make impossible to fix by introducing modules.

Thanks. The sticking point is what degree o= f change should be occurring. PHP isn't as behind an 8-ball as JavaScrip= t is since the dev can choose their PHP version and hence deprecation wo= rks most of the time for getting rid of old stuff. But not always. Chang= es that are incompatible with what came before need a way to do things t= he old way during transition. Again, see PHP 6 and unicode, which snowba= lled until it was clear that even if PHP 6 had been completed it wouldn'= t be able to run most PHP 5 code.

It=E2=80=99s not just up to the dev, but the= libraries we use and whether or not we can easily upgrade (or remove) t= hem to upgrade the php version.

 
2. No need for autoloaders with modules; I assume this would be = obvious, right?


Depends largely on whether modules can include and require to get= access to old code. I also didn't discuss how they behave - do they sha= re their variables with includes and requires?

I think it would be a mistake t= o exclude old code and/or prevent templating. Not only are there now dec= ades old code in some orgs, but how would you write an email sender that= sent templated emails, provide html, generate code, etc? There has to b= e an output from the code to be useful. 

&nbs= p;

3. Not a good idea to use an ini se= tting; most view them to be problematic.
4. .htaccess =C3=AE= s Apache-only, so a non-starter anyway.
5. The first scrip= t should not be a module. If you want that, have a 1 line index.php file= do an import.

I love th= is idea. 

 
6. Modules should be directories, not .php files. Having ea= ch file be a module makes code org really hard.

Yes, but that is how JavaScript currently handle= s things. It is currently necessary when making large packages to have a= n index.js that exports out the public members of the module. This entry= point is configurable through the package.json of the module.
=

I think it=E2=80= =99s fine to use js as an inspiration, but it isn=E2=80=99t the only one= out there. There is some precedent to consider directories as modules (= go calls them =E2=80=9Cpackages=E2=80=9D) and especially in PHP where na= mespaces (due to PSR-4 autoloading) typically match directory structures= .

For example, I=E2=80=99m still going to g= o forward with my #[Internal] attribute RFC some time in the next month = or so, which will be namespace based. I have no idea if it will pass, (s= ome people are worried about it clashing with an RFC like this one) but = I think we=E2=80=99d have value in it for years to come until something = like this gets fleshed out. We will see=E2=80=A6 

=
 
7. Modules would have a symbol table meta= data file generated by IDEs and during deployment.

Node.js uses package.json and the attendant n= pm to do this sort of prep work.  And it's a critical part of this = since modules can be versioned, and different modules may need to run di= fferent specific versions of other modules.
<= /div>

Please, please, please do not make= a json file a configuration language. You can=E2=80=99t comment in them= , you can=E2=80=99t handle =E2=80=9Cif php version <9, load this, or = if this extension is installed, use this.=E2=80=9D

Maybe that is desirable, but doing things slightly different bas= ed on extensions loaded is def a thing. 

&nbs= p;
8. If no metadata file in directory PHP can g= enerate one in memory during first directory access. 
9. .php files in modules as identified by metadata file should not be l= oadable via HTTP(S). 

Those are implementation details a little further down the road than = we're ready for, I think. 

Personally, if these are going to have any spe= cial syntax, we probably shouldn=E2=80=99t call them .php files. Maybe .= phm?

=
 

10. = Having exports separate from functions and classes seems like it would b= e problematic.

Again, th= is is how they work in JavaScript. Not saying that's the best approach, = but even if problematic it's a solved problem.

the only thing I don=E2=80=99t = like about this import/export thing is that it reminds me of the days wh= en we had to carefully order our require_once directives to make sure fi= les were loaded before they were used. So, I think it is worth thinking = about how loading will work and whether loading can be dynamic, hoisted = out of function calls (like js), how order matters, whether packages can= enrich other packages (like doctrine packages) and if so, how much they= can gain access to internal state, etc. This is very much not =E2=80=9C= a solved problem.=E2=80=9D

 
11. Exports could be implemented as attributes, which could be re= ally elegant.
12. Exports as attributes pairs with the sym= bol on the line above, and would enable easy aliasing.

Ultimately everything in JavaScript is an= object. JavaScript provides a mechanism for handling a module file with= a single default export, but it supports multiple exports from the same= file which arrive as an object best approximated in PHP as a static cla= ss. I could hash out further, but again, I'd like to gauge some interest= and very high level feedback. I'm also interested in learning on how ot= her module systems out there do work. I'm picking of JavaScript because = most of the PHP community has to use it as well for client side scriptin= g and so most of us should have at least passing familiarity with it.

In JavaS= cript, arrays are instances, in php, they are values. This is something = to consider if a module exports an array of exports. 
<= div class=3D"qt-gmail_quote">
 

13. And finally, when = are you starting the RFC?  :-)
It's too early for anyone to start at this moment - and whil= e I certainly am willing to help I'm not qualified to take the lead on t= his.
 
If adopted, this is a massive ch= ange, and the results of this conversation won't hit for years. Let's ta= ke our time. For one, this overarching project will need multiple coordi= nated RFC's, as well as figuring out what to do and also in what order.<= br>

=E2=80=94 Rob
--90048e65cc0e4158bf652b6f0f6902eb--