Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126848 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 2C3441A00BC for ; Wed, 19 Mar 2025 19:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742412145; bh=C6j1ydZ4Gs/JK0WKZ6ztOn/w/mK0rNz3Deaqo2tXW74=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=BQKo1lqxueJIWYFhDYA1OxlwPDiJWqmQmqynyAQhgFlP6JGzsk4Y+4slL5/pso34K EiWp7uNtlB+XMh+WyGIWVzJ9MJ4kEukW5XoPGgyBRaJHhyqI5Fgn2kiQXVcatOZKtn cDhzhFQz2QQIYDMUpvNHCuL3Ih8sEsTjzQEQIprOVRObUklImFDPykItyXnMcDb440 rrcKoHx768AKiq1Uk9bo7VflPdYoCNfXnaliT8u7pJgUJ0azDy29hRqyoz7bnSqAPJ K2xYZ58Ov9LoUGkszFsjADURxsge5hSYiaT+tc+ui1HOqf95ygwQaFjG0UimPLMSOf t39oc3ktT0AWQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DAAFE18005B for ; Wed, 19 Mar 2025 19:22:24 +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=-2.0 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (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 ; Wed, 19 Mar 2025 19:22:24 +0000 (UTC) Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-e4930eca0d4so5664993276.3 for ; Wed, 19 Mar 2025 12:24:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742412295; x=1743017095; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SY1CxMsl/iPX/bFWWGap58EoQ00yGAIHKDX6rzhFNzY=; b=AZAp9ZbRaHgEZAheZRGey50jbFmQegIPRj2IiQaISq9W4Pn5aJjeNIhes/yteYbmRD oBwkT9Ni2l9FNq+Opz+o8rFLmvi1//SrZglQy5IKzYYYqOOz0z0JSecJ3xIeQ7cqI5as QZz729pjgogSXO4l0HJBSDTJsKwnqFf0Is1GgO3JU2Rtry6X/Ig1iOMmLDzDg0EdrSpA ZPZtLgJKrX2/RIBQwsIDxjNarLzoTW99SgJQKq2yfJigtAzGG4PL7UuAYtWwGwuwEMy3 S3VY0KULeF03+xKleY3M/G7gkI4cXp+XN6BVsOVpRK+BkaLsItWIwPMHaFyFDO0d8vV9 TzZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742412295; x=1743017095; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SY1CxMsl/iPX/bFWWGap58EoQ00yGAIHKDX6rzhFNzY=; b=uDo3/3EaY7poioSo0pSd6duwhk32QapccOLX1rshb5IWN6imAhTcdfAK4sdXn1Nycr u1RaIQgVobgDQfHEpemTa2+QChyH78L0Dj35gNVg+Q5KVytUQgLtamunmB4qOKbU2ZT9 r+IlyrmlwJOcvbL1pNAwe45ZifWlk6OUTE5gA2vx4LmMyLZm8AfIsZ/Mv/wdVVzdRsSq yVIAzj4tLGK1r0ojjxvOaOhwTl9SftOX3QuDVZ8AEE52Z5xhZZbF2zUmNqoeZ7qQ5+Oa UROdn21LXPtLPgNwtNBSX5dbZwByt1EE9QpWg0Oxk+UiA/jjWimLDMYXL9ezCYpwKo2N jy7g== X-Gm-Message-State: AOJu0YyExKkNM0q8HMCCZx+IGVyhjO0tgtXOUUGO7N32SorflZGXPY1g SKhhggSJKI+LiE138G8srw98gpFyLUfW8R1Wna5hzgx+xKsz9s4CpxUPDJwNbh0vTGE/RTxc/Sa IGz5J/TngFODe6yC9ynQC4fhfb9s= X-Gm-Gg: ASbGncv3dPBm9s9E2gxnljvxi21kuR7ctTiA6a2yiXQlLOy2bySnpYClKuTfDQ5qWWU 2mJjIntkFrimOFmMA9Fnn1/64coG9XiIsmoKP2V8ZnaDumxXQUdP1RbxvIF9AK7pPU6CtDywvOS bFpu6gg9xIvzQBehDfK/PpWMVCwQ== X-Google-Smtp-Source: AGHT+IHQH/ZibM3DpkJRrEwtNErpNNMERlyR1nJBkxiNh/W9fhzQbEibPErA5QwbIznuQ0pwjMUOozyue+Z9VzRx37U= X-Received: by 2002:a05:6902:2087:b0:e5d:cd08:12f0 with SMTP id 3f1490d57ef6-e6692122f80mr606899276.44.1742412295072; Wed, 19 Mar 2025 12:24:55 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <72bd5401-53a9-409f-ad45-687333401961@rwec.co.uk> <6987D912-CE46-4145-A8CE-732CA590A522@rwec.co.uk> <2F013672-9937-4AB1-BC46-86F3D342BE6B@rwec.co.uk> In-Reply-To: <2F013672-9937-4AB1-BC46-86F3D342BE6B@rwec.co.uk> Date: Wed, 19 Mar 2025 21:24:43 +0200 X-Gm-Features: AQ5f1JrIxiL_D4bdvWzg-5Bj391TYarP5cAobvTaOK4howN5gpOP14DcgSU-YHQ Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC - Stage 2 To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000e6786a0630b6f95e" From: edmond.ht@gmail.com (Edmond Dantes) --000000000000e6786a0630b6f95e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > But even though we're talking in circles about why, > your latest examples do avoid the particular problem I was trying to describe. > I thought the problem was that the syntax wouldn't work. Is there any other issue? > > Yes, that would probably be a bad choice as well. Which is why I've repeatedly suggested a different keyword, and AFAIK you still haven't actually voiced an opinion on that. > Does this concern the syntax of `spawn block {}` or did I miss something? I will describe the reasons why I rejected the concise syntax in favor of a more verbose one below. > > But you kept referring to that token as "expression", which confused me, because that's a different thing in the grammar. > By the word "expression," I mean a language construct along with keywords. If `spawn function_call` returns a value, then it can be considered an expression, right? Or am I mistaken in the terminology? > > I think I asked this before: why would anyone want to specify a return type there? > A simple answer (though not necessarily the correct one): because it=E2=80= =99s a closure. And in PHP, a closure has a return type. I understand what you're asking: what is the practical significance of this? Perhaps none, but it provides consistency in syntax. The syntax `spawn {};` is the most elegant in terms of brevity. There's no doubt that it's shorter by the number of characters in "function". - `spawn block {};` also looks decent. However, the keyword `block` does not accurately reflect what is happening, because what follows is n= ot a block but a closure. - `spawn closure {};` is a possibility, but it raises the question: why introduce the keyword `closure` when we already have `function`? The difference in characters is minimal. - `spawn fn {};` is the shortest option, but `fn` is already used for the shorthand function syntax `fn() =3D> ...`. But we can forget about `ReturnType`, right? Okay, but there's another point. In PHP, code blocks are not all the same. - `if` / `then` / `else` / `try` / `switch` **do not create a new scope**. - `function` **does create a new scope**. When a programmer writes: ```php $x =3D 5; spawn {$x++}; ``` Will they easily understand that $x++ is not modifying the same $x as before? No, they won=E2=80=99t. They will have to remember that spawn {} creates a = closure, just like function creates a closure with a separate scope. This means the programmer has to remember one extra rule. The question is: is it worth the additional "function" characters? Though, I don=E2=80=99t mind `spawn fn {};`=E2=80=94this option takes the b= est of everything. But if we implement it, I would also introduce the `fn() {}` syntax. ``` spawn fn use($x) { ... }; ``` Apart from violating the language's style, I don't see any drawbacks for this. --000000000000e6786a0630b6f95e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>
>=C2=A0But even though we're talking in circles about why,
&= gt; your latest examples do avoid the=C2=A0
particular problem I was trying to describe.
><= div>I thought the problem was that the syntax wouldn't work. Is there a= ny other issue?=C2=A0=C2=A0

>
>=C2=A0 Yes, that would probably be a bad choice as well. Which is why I've rep= eatedly suggested a different keyword, and AFAIK you still haven't actu= ally voiced an opinion on that.
>

Does this concern the sy= ntax of `spawn block {}` or did I miss something?=C2=A0=C2=A0
I will describe the reasons why I rejected the concise syntax in favor of = a more verbose one below.=C2=A0=C2=A0

>=C2= =A0
> But you kept referring to that token as "expression",= which confused me, because that's a different thing in the grammar.
>

By the word "expression," I= mean a language construct along with keywords.=C2=A0
If `spawn f= unction_call` returns a value, then it can be considered an expression, rig= ht? Or am I mistaken in the terminology?

><= br>>=C2=A0 I think I asked this before: why would anyone want to specify a return type= there?
>
A simple answer (though not necessarily the corre= ct one): because it=E2=80=99s a closure. And in PHP, a closure has a return= type. =C2=A0
I understand what you're asking: what is the practical= significance of this? Perhaps none, but it provides consistency in syntax.= =C2=A0

The syntax `spawn {};` is the most elegant = in terms of brevity. There's no doubt that it's shorter by the numb= er of characters in "function".=C2=A0=C2=A0
    `spawn block {};` also looks decent.=C2=A0 However, the keyword `block` do= es not accurately reflect what is happening, because what follows is not a = block but a closure.=C2=A0=C2=A0
  • `spawn closure {};` is a possibili= ty, but it raises the question: why introduce the keyword `closure` when we= already have `function`? The difference in characters is minimal.=C2=A0=C2= =A0
  • `spawn fn {};` is the shortest option, but `fn` is already used= for the shorthand function syntax `fn() =3D> ...`.=C2=A0=C2=A0
  • But we can forget about `ReturnType`, right? Okay, but there's an= other point.

    In PHP, code blocks are not all the same. =C2=A0<= br>- `if` / `then` / `else` / `try` / `switch` **do not create a new scope*= *. =C2=A0
    - `function` **does create a new scope**. =C2=A0

    When a= programmer writes: =C2=A0
    ```php
    $x =3D 5;
    spawn {$x++};
    ```
    Will they easily understand that $x++ is n= ot modifying the same $x as before?
    No, they won=E2=80=99t. They will have to remember that spawn {} creates a closure, just like function creates a closure wit= h a separate scope.=C2=A0

    This means the programme= r has to remember one extra rule. The question is: is it worth the addition= al "function" characters? =C2=A0

    Though, I don=E2=80=99t m= ind `spawn fn {};`=E2=80=94this option takes the best of everything. But if= we implement it, I would also introduce the `fn() {}` syntax.=C2=A0=C2=A0<= br>

    ```
    spawn fn use($x) {
    =C2=A0 =C2= =A0 ...
    };
    ```

    Apart from violating t= he language's style, I don't see any drawbacks for this.=C2=A0=C2= =A0
--000000000000e6786a0630b6f95e--