Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123933 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 4CBC41A009C for ; Thu, 27 Jun 2024 10:09:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719483036; bh=vALGP3mV5SC2lMvfSIN2LUEjiCCDGgImEAR9jkjyNbI=; h=In-Reply-To:References:Date:From:To:Subject:From; b=gkXWtb/GlkWGHyzch+7XV+wFNHCeZNfsg4wa8cO79X4Oz3lEaJggofUt/+GM9aKPy EbEDPYgY7TD58XuWCsFCC4vRv03WhJjlQu/kVyodwfWmpu8L3GOZD7Cgg+Eb+hNfHM BOi3wOPtAur049rPzGtdlMG6PtYpva+B7aOXS3RsPuSR3kA5qUGWDlw0C79hSFXF5p CHNi5C4yNhWbZTnnyTIxecrSbQZWfwAvto7XwaTYF7hrQ0ak3qCCS/0GfcR4uq32Ur s76lEGXGmjpNyhbXXXj9TRBlFTMnAEt+yfq2SiHRehBHrzdZ4x2ecMHbsrUbANhLNG 8yyicAELMgYsA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DEA1C180A57 for ; Thu, 27 Jun 2024 10:10:34 +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 fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 10:10:34 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C25DC114037C for ; Thu, 27 Jun 2024 06:09:15 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Thu, 27 Jun 2024 06:09:15 -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=1719482955; x=1719569355; bh=OBHa2dTurG HkhVbl1svjU5zQLr5NCvU14A3aoKqcEuo=; b=Vq4crGEx/80fAhtl+psZtShh6B 4XDFrpnNYrfK1LOUSVGPVuHwk0VgntoKPuBJugzO5iWbe4buoL99bwMEq6+S0Z5E 2LDyztpkLRIRnGpnnV9BBhMfbDXpNMh6S6d3f/8I+j0hOFWKF7F1tjDv3qp3CtBo TnqIFD7HCuuu5XEq/QP6u4a/RmfqNh9s7Asv05N91gRJmW5DJhiQr3C7aUJw408D XtzlxRSfteZOawPn2FhnHkDznNvVZflVIAB+n3EwQHx679B2K6Rkyr1V+t0cXTVI EHuJynREnS0wDUBMXiu2wJvIGTaSpvau/ywvP/upcKtdWYoGHtlPAH0fyxIw== 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=1719482955; x=1719569355; bh=OBHa2dTurGHkhVbl1svjU5zQLr5N CvU14A3aoKqcEuo=; b=LhiItTVcHNc5EWlpXayyABK2omynsPZTV1X7yAil32OJ DV6njvo+5PbcRcw28HlZHQbs67VLydQUCatcv8/vfPVK01BVitaACdHUyH87ojnK UJKEy48Po//9jKNnvth4vOovW7kc1dkYNmgeo0hbVjENGtrQCA3LoBMOmRPYMFEe HAPiGjZnPuqUAU1jzeJC+24uzwIcibVesA55/+l5j86U+glMkk82NF9HbVzxSRy4 yZvSDIzRxOOiz80SQapWyB7M5XlTx6xwjaLnSNTgN6Cjz2qtpT2qNp0ATn/tB2WG 1wCc2VchUWvwvFhscxByOtIoJbPqAYni364zZVh5kA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtdeggddvhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecuogfuuhhsphgvtghtffhomhgrihhnucdlgeelmdenuc fjughrpefofgggkfgjfhffhffvufgtsegrtderreerreejnecuhfhrohhmpedftfhosgcu nfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrth htvghrnhepffdvteegleevgeduvefhheffgeehtdduteffgfejhfevgfehffdvhffhveeg geeunecuffhomhgrihhnpeefvheglhdrohhrghenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghs X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 5EBFB15A0092; Thu, 27 Jun 2024 06:09:15 -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: <278240fc-f92d-450f-b7cd-6ea8b6a37367@app.fastmail.com> In-Reply-To: <1dfa55cb-5789-4090-aa10-f343fd8c4820@app.fastmail.com> References: <1dfa55cb-5789-4090-aa10-f343fd8c4820@app.fastmail.com> Date: Thu, 27 Jun 2024 12:08:50 +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=f1ced656c49c4daab25c3d7fac6ac2cb From: rob@bottled.codes ("Rob Landers") --f1ced656c49c4daab25c3d7fac6ac2cb Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Jun 27, 2024, at 09:41, Rob Landers wrote: > 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 m= y head for a few days now. It isn't fully formed, but I've ran the thoug= ht 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. O= f those not accepted many have been passed over because of background co= mpatibility. And then there is the issue that PHP has multiple design fl= aws that seem impossible to get rid of. Finally, I sense from conversati= ons I've read that there are a lot of engine parser optimizations that h= aven't been tried because of the background compatibility problems prese= nt. >>=20 >> JavaScript was in this position as well 10 years ago when JavaScript = modules were introduced with the ES6 syntax. Only recently have these mo= dules finally begun to become first class members of node.js. The exist= ing CommonJS require mechanism remains and will remain in Node for the f= oreseeable future, but the ES6 syntax allows an opportunity to sidestep = the issue. The most significant of these is JavaScript modules run in st= rict mode, which actually removes features that are problematic for the = engine 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 = vantage point: I am but a humble user of the code, I'm no expert on the = underpinnings of the Zend engine. In the text to follow I'm going to mak= e 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 un= dertake. >>=20 >> So all that said, I'll begin. >>=20 >> PHP User Modules are php files that are brought into the runtime thro= ugh a new parser that is able to generate faster and more concise runtim= e code by removing support for problematic features and imposing a stric= t mode by default. They focus on PHP as a language and not as a template= engine. >=20 > FYI, in non-strict mode, this produces a deprecation warning that can = be caught and thrown from: >=20 > (fn(int $x) =3D> print($x))(123.456); // deprecation warning >=20 > but this will work >=20 > (fn(int $x) =3D> print($x))(123.000); // this is fine >=20 > Both of those are errors in strict types, so you might be tempted to do >=20 > fn(int $x) =3D> print($x))((int)$some_var); >=20 > but $some_var might not actually be an integer-like (such as null or a= string that becomes zero). >=20 > Some of us prefer the more strict, non-strict mode as the built-in str= ict mode is actually ... uhh, problematic, to say the least, in some bus= iness cases. So forcing strict mode is probably a non-starter. If you want to see what I mean: non-strict: https://3v4l.org/kZ09l strict: https://3v4l.org/5kVSG =E2=80=94 Rob --f1ced656c49c4daab25c3d7fac6ac2cb Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Thu, Ju= n 27, 2024, at 09:41, Rob Landers wrote:
On Thu, Jun 27, 2024, at 04:15, Michael Mo= rris wrote:
<= div dir=3D"ltr">
Hello all. This is a ramble of an idea that's manag= ed 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 sh= are 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 m= any have been passed over because of background compatibility. And then = there is the issue that PHP has multiple design flaws that seem impossib= le to get rid of. Finally, I sense from conversations I've read that the= re are a lot of engine parser optimizations that haven't been tried beca= use of the background compatibility problems present.

=
JavaScript was in this position as well 10 years ago when Jav= aScript modules were introduced with the ES6 syntax. Only recently have = these modules finally begun to become first class members of node.js.&nb= sp; The existing CommonJS require mechanism remains and will remain in N= ode for the foreseeable future, but the ES6 syntax allows an opportunity= to sidestep the issue. The most significant of these is JavaScript= modules run in strict mode, which actually removes features that are pr= oblematic for the engine or make it difficult to create optimized code.<= br>

Something similar could be done in PHP, and= that's what the remainder of this letter is about, but before I continu= e I want to make clear my vantage point: I am but a humble user of the c= ode, I'm no expert on the underpinnings 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 undertake.

So = all that said, I'll begin.

PHP User Modules= are php files that are brought into the runtime through a new parser th= at 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.
<= /div>

FYI, in non-strict mode, this prod= uces a deprecation warning that can be caught and thrown from:
=

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

but this will work

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

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 string that= becomes zero).

Some 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 business cases. So forcing stric= t mode is probably a non-starter.

<= div>If you want to see what I mean:

non-str= ict: https://3v4l.org/kZ09l<= br>

=E2=80= =94 Rob
--f1ced656c49c4daab25c3d7fac6ac2cb--