Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123930 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 7A62A1A009C for ; Thu, 27 Jun 2024 07:41:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719474183; bh=+fuV4dNwXlLSDwAoTop0cxiXGjqjscPvF81plBRlKxs=; h=In-Reply-To:References:Date:From:To:Subject:From; b=c36OwFMhuRCcoowqscLEjrfANlCbYV6dxKWL/sh5JJLaNfsLcipe1x50JUsQeeLnL D5yxVtvd0CX9W+HrCY5bbqDtLuS7jfzmAApezdniPOhuiKI4ZFNh8R6Xrh+lTPnVTD TBR9lyWf34m10/DpGqTacANPzJEnyEyWJ/jvklNzC1TtAdUS5HVfZx0V0s/3slptNT XlMVEWmnIoXEAf9ddS9awCuwex9gpD3KvupH9gl3MLbFZA2U4Bq3NWq4hpabcb8ix3 /xXN2uvdhNbPfImQtsVP429IZ+FDu+i1JoPJHvtt5gVwZ0mK1IQEukHJqnIG2ohL9z +COTKWcc3tMOA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 53704180685 for ; Thu, 27 Jun 2024 07:43:02 +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 fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 07:43:01 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 86B2C13804D8 for ; Thu, 27 Jun 2024 03:41:43 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Thu, 27 Jun 2024 03:41:43 -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=1719474103; x=1719560503; bh=ESb1df2TmX WVSBXybpIzKtd2kRX7iNZbVb2w/BNEfAo=; b=iuGzzElzgnOI/+o0+IBHS7cGRI bmJMterGzpmeAOedFomIlg1nZZtw1sgu4LzcKDIxad2DfHmM77X2XJuCrqqhp+O+ nQtFev2f3TlRDgv7xgm3BAjDWSsIGciLHyBk68Vo0HrN+dcbvW7HmscknbjN5F5b QG4eg5JBVuRV6Uqkf10/1Drkoy/6egE/lyYWVTuTy2nxSWUZzK6bYGRFZmlJkI/x n/rJLuTwpBOngN7kpU1G/13aWZq866dZ2stpHAbh7NhpmBdBIYlsVpWaj4KQA26l CiZTxHnh86b9dS9cBpZjiYMnqKtMpUUdYWWq6aIcBZvGOC5cwHXn5rI+6ZVw== 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=1719474103; x=1719560503; bh=ESb1df2TmXWVSBXybpIzKtd2kRX7 iNZbVb2w/BNEfAo=; b=OzV1Fe6Wj8qcPacZZrGKdTsbZoFoPGy1bDm0bsgrqAse LgOdAiAmavcaPLUrc8HJ+6PgWyNXq1LblqynR/3OnleF5XNvgyerUp7vbcLSFhLJ 88mWZbU3crurCaOQKOJVbKsnSCmn3rUPCEiISkLevV4HYW7T/7pBUjFR3Mw9gOnZ 3z89BpcBkeOexcSoemyTdqYxcFMdbProWC7HSgJOWinRggg9UAeaAcPgYeayfkxl kuWKmSclLxeaMlvDXheiRRAPqR2jsv65UuF5m0fiw3UfaTx11uQTIoo4DL5tzx2k CmLIK1ltRd2pHMZ2khKSMs6Gb/6X0N89++/FLZpCbg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtdefgdduvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsegrtd erreerreejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothht lhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepfeefudfhudduieekkedugffhud fgleejgfekgefhvdeikeelvddvjeehteegteegnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvsh X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id D19A215A0092; Thu, 27 Jun 2024 03:41:42 -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: <1dfa55cb-5789-4090-aa10-f343fd8c4820@app.fastmail.com> In-Reply-To: References: Date: Thu, 27 Jun 2024 09:41:21 +0200 To: internals@lists.php.net Subject: Re: [PHP-DEV] [Initial Feedback] PHP User Modules - An Adaptation of ES6 from JavaScript Content-Type: multipart/alternative; boundary=2ac585f0f3d64c6b9bc59052ba7e44c9 From: rob@bottled.codes ("Rob Landers") --2ac585f0f3d64c6b9bc59052ba7e44c9 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Jun 27, 2024, at 04:15, Michael Morris wrote: > Hello all. This is a ramble of an idea that's managed to run around my= head for a few days now. It isn't fully formed, but I've ran the though= t experiment as far as I can on my own and want to share it with all of = you. >=20 > I've mostly been a lurker and I've seen a lot of RFC's come and go. Of= those not accepted many have been passed over because of background com= patibility. And then there is the issue that PHP has multiple design fla= ws that seem impossible to get rid of. Finally, I sense from conversatio= ns I've read that there are a lot of engine parser optimizations that ha= ven't been tried because of the background compatibility problems presen= t. >=20 > JavaScript was in this position as well 10 years ago when JavaScript m= odules were introduced with the ES6 syntax. Only recently have these mod= ules finally begun to become first class members of node.js. The existi= ng CommonJS require mechanism remains and will remain in Node for the fo= reseeable future, but the ES6 syntax allows an opportunity to sidestep t= he issue. The most significant of these is JavaScript modules run in str= ict mode, which actually removes features that are problematic for the e= ngine or make it difficult to create optimized code. >=20 > Something similar could be done in PHP, and that's what the remainder = of this letter is about, but before I continue I want to make clear my v= antage point: I am but a humble user of the code, I'm no expert on the u= nderpinnings of the Zend engine. In the text to follow I'm going to make= wrong calls on some things - maybe multiple things. I'm not married to = anything here. Further, even if I were a master of the engine and knew = where to start, the scope of this is too large for any one person to und= ertake. >=20 > So all that said, I'll begin. >=20 > PHP User Modules are php files that are brought into the runtime throu= gh a new parser that is able to generate faster and more concise runtime= code by removing support for problematic features and imposing a strict= mode by default. They focus on PHP as a language and not as a template = engine. FYI, in non-strict mode, this produces a deprecation warning that can be= caught and thrown from: (fn(int $x) =3D> print($x))(123.456); // deprecation warning but this will work (fn(int $x) =3D> print($x))(123.000); // this is fine Both of those are errors in strict types, so you might be tempted to do fn(int $x) =3D> print($x))((int)$some_var); but $some_var might not actually be an integer-like (such as null or a s= tring that becomes zero). Some of us prefer the more strict, non-strict mode as the built-in stric= t mode is actually ... uhh, problematic, to say the least, in some busin= ess cases. So forcing strict mode is probably a non-starter. >=20 > The only background compatibility break is the introduction of three k= eywords: "import", "export" and "from" >=20 > The PHP interpreter does not load PHP files as modules unless it is di= rected to do so in an ini file or an .htaccess file using the default_fi= letype directive. If this directive is missing its value will be "defau= lt" - the value "module" will be used to trigger loading the initial PHP= file as a module, and further types could in theory be introduced at a = far later date. >=20 > Again, this setting only affects the INITIAL PHP script file loaded by= the interpreter, such as the index.php of Drupal. Files that are includ= ed with include, include_once, require, or require_once will be imported= as they always have. Files that are included with import are PHP User = Modules. One of the advantages of the current autoloading file-loading system is = that files are not included until the are used. This allows you to run M= ASSIVE projects that realistically only need to load dozens of files. Fo= r example, I know of some code-bases that have literally millions of PHP= files collected over the last 15 years and hundreds of developers worki= ng on them every day. >=20 > User Module Files > PHP User Modules have the following properties (Proposed, and very muc= h subject to change): > * They are code files. They have no tags, and the inclusi= on of those tags is a parse exception. I know this will be problematic f= or PHP storm and other IDE's, but it's not an insurmountable problem. So, will ?> work? I have turned on output buffering and then just wrote = out what I needed --- ie, a template, then get the output.=20 > * If the removal of HEREDOC and NOWDOC syntax would simplify the parse= r, then these too would be removed from User Modules. Are we sure we want *multiple* PHP parsers to maintain? =E2=80=94 Rob --2ac585f0f3d64c6b9bc59052ba7e44c9 Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Thu, Jun 27,= 2024, at 04:15, Michael Morris wrote:
Hello all. This is a ramble= of an idea that's managed to run around my head for a few days now. It = isn't fully formed, but I've ran the thought experiment as far as I can = on my own and want to share it with all of you.

=
I've mostly been a lurker and I've seen a lot of RFC's come and go.= Of those not accepted many have been passed over because of background = compatibility. And then there is the issue that PHP has multiple design = flaws that seem impossible to get rid of. Finally, I sense from conversa= tions I've read that there are a lot of engine parser optimizations that= haven't been tried because of the background compatibility problems pre= sent.

JavaScript was in this position as we= ll 10 years ago when JavaScript modules were introduced with the ES6 syn= tax. Only recently have these modules finally begun to become first clas= s members of node.js.  The existing CommonJS require mechanism rema= ins and will remain in Node for the foreseeable future, but the ES6 synt= ax allows an opportunity to sidestep the issue. The most significant&nbs= p;of these is JavaScript modules run in strict mode, which actually remo= ves features that are problematic for the engine or make it difficult to= create optimized code.

Something similar c= ould be done in PHP, and that's what the remainder of this letter is abo= ut, but before I continue I want to make clear my vantage point: I am bu= t a humble user of the code, I'm no expert on the underpinnings of the Z= end engine. In the text to follow I'm going to make wrong calls on some = things - maybe multiple things. I'm not married to anything here.  = Further, even if I were a master of the engine and knew where to start, = the scope of this is too large for any one person to undertake.

So all that said, I'll begin.

PHP User Modules are php files that are brought into the runtime= through a new parser that is able to generate faster and more concise r= untime code by removing support for problematic features and imposing a = strict mode by default. They focus on PHP as a language and not as a tem= plate engine.

FYI, in no= n-strict mode, this produces a deprecation warning that can be caught an= d thrown from:

(fn(int $x) =3D> print($x= ))(123.456); // deprecation warning

but thi= s will work

(fn(int $x) =3D> print($x))(= 123.000); // this is fine

Both of those are= errors in strict types, so you might be tempted to do
fn(int $x) =3D> print($x))((int)$some_var);

but $some_var might not actually be an integer-like (suc= h as null or a string that becomes zero).

S= ome of us prefer the more strict, non-strict mode as the built-in strict= mode is actually ... uhh, problematic, to say the least, in some busine= ss cases. So forcing strict mode is probably a non-starter.


The only background compatibility break is the i= ntroduction of three keywords: "import", "export" and "from"

The PHP interpreter does not load PHP files as modules= unless it is directed to do so in an ini file or an .htaccess file usin= g the default_filetype directive.  If this directive is missing its= value will be "default" - the value "module" will be used to trigger lo= ading the initial PHP file as a module, and further types could in theor= y be introduced at a far later date.

Again,= this setting only affects the INITIAL PHP script file loaded by the int= erpreter, such as the index.php of Drupal. Files that are included with = include, include_once, require, or require_once will be imported as they= always have.  Files that are included with import are PHP User Mod= ules.

One of the advanta= ges of the current autoloading file-loading system is that files are not= included until the are used. This allows you to run MASSIVE projects th= at realistically only need to load dozens of files. For example, I know = of some code-bases that have literally millions of PHP files collected o= ver the last 15 years and hundreds of developers working on them every d= ay.

<= div dir=3D"ltr">

User Module Files
PHP = User Modules have the following properties (Proposed, and very much subj= ect to change):
* They are code files.  They have no = <?php or ?> tags, and the inclusion of those tags is a parse = exception. I know this will be problematic for PHP storm and other IDE's= , but it's not an insurmountable problem.

So, will ?> work? I have turned on output buffering= and then just wrote out what I needed --- ie, a template, then get the = output. 

* If the removal of HEREDOC and NOWDOC sy= ntax would simplify the parser, then these too would be removed fro= m User Modules.

Are we s= ure we want multiple PHP parsers to maintain?

=
=E2=80=94 Rob
--2ac585f0f3d64c6b9bc59052ba7e44c9--