Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126838 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 3FFCD1A00BC for ; Wed, 19 Mar 2025 11:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742383492; bh=7mfJxpOsNkzZ1mMaMnPHdwd2DM8Ch7H0q9MUu55/5KI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Vn4sURzeD9VLhbt/eVxz0vQw8TUKEpZxRKm+EZlB6MK0Z8LO7kmOKDMEurePdJ/l3 llIIC5JKke5zpJcslKx0x20bNHEdMjJoI/7/pjgpkDoDHuagsQe8rUeW3V7Yb+x0pB 7Ip8kIEvOFKPv6bzhP71S4UGjHGbwJKOoxqkm6ocUTiNND0scxUnNr9drJNs7YTT2Q OoHekEjGCKEVX5MyCrBGirQQ5QjVRM3L6WvE11ETkz39XmqmIOEgBAMy02pODZnwu3 O3HyUmvVuf3jDbDfP5ucyX+pA1jE21X0Yssa1BIlHGYJW5QrjUk9TWm3pavQc9woQy 0yj74dtTVTXMA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CEFC4180390 for ; Wed, 19 Mar 2025 11:24:51 +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=-3.9 required=5.0 tests=BAYES_00,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-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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 11:24:51 +0000 (UTC) Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e5ad75ca787so580106276.0 for ; Wed, 19 Mar 2025 04:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742383642; x=1742988442; 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=OlI2XymRSZ5xLOzK501jOoe4DIanZagvhgTr9tyK1Xk=; b=LqOZ0Prz7gkHpZXgUoNbbAMlco7hU+GvEj88zHNSpq43mxgkGtAxn/hoqhceBT+3tV iao7kaiSsZssmQN4BRHCibySj5W/Oti1SiSwkR8+w1NqMP4JRsvp23El81PIHPZVEC62 SMGfhC2CenZcV23Ub5nBW/2zvsWXn5sJuDnI6BCJKRoXWIzp1UG/fwfUcqNLyQUnPlDt PDDZtJMzpD2uBvjn0AFvDbcYLdg3aBFYlt/UMKjYZxMGYfCoxPZGEec5qlzlRz8ZRDrx cS7SSAKjMh5XZO/maNqD0SCSb6n5fleCqTIIR/91iPS9kdxKuCxgTUOfnMrWTHrS+FlC qfcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742383642; x=1742988442; 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=OlI2XymRSZ5xLOzK501jOoe4DIanZagvhgTr9tyK1Xk=; b=rxwnpXirIoRBlplarNKRrdwFlQNTtTC4mBIn3h5tFtg4WFOPbJOPaauBzyU8XFXL5X W2Gk7FJ7Qo/QwQnDZ21cz6AooHtIYHGDfhOh6wrxfgJC7wxrRLfwdI4Kr0Lxflty/bod aXXkuObXD+wCyKmNAAzJQpRSpr7WMStADEFo7I5T5ivoFwv+1e9N1tGpkP5/8UA6FwWK 6qE9I3QwTyolQoiao6StLq7y+0soFUUhAzFC4Mv2wprHEmHiVLtrCCAmb8JRQa83BDcm 2h/EOU1pHcgMgoFsbWNN5YQ/uoNj0YQS6iUNLSV3uIqCukGJK4lHuYbpiNPU625kvK29 HB4w== X-Gm-Message-State: AOJu0Ywp2yAlJhnp+XgcMpoeW5M0PVy191Zje55ki5iCYjqJOxsVY70q jY2r+yuksmfdH+CmUK2Z73Iu2N5ff6bdSGpcI/PKKAMB/f2ZixVSzuAqts0hH3+nOnOj7SjETsu 32REIJ2rQrIMEdI0xXPwT2NJQ6yEJy9N6pGw= X-Gm-Gg: ASbGncsTFRl20ONX57vwHJSSN7BOBQXat6M5qM0+pUEKeZHZCOvbKLQM21u97YzjIIb yo76IKOQankLZxVyYQxdjWzddQDOAZsEQqIPXC0CkwpKsr7PO4blwEI1mNmkF7MvT6DWiQKLi8H 1a0I2xrw5oHIyAWHhBwwbvXnM5cQ== X-Google-Smtp-Source: AGHT+IEzkDjb6fAAggvunNBRzWJM4kcZna9KYy1k9JByS1nDmAqtiQbZ4++JN6ydY8fDwqH9AlMNQqw8wGbh90qv/U0= X-Received: by 2002:a05:6902:2291:b0:e5d:c1b9:4a7 with SMTP id 3f1490d57ef6-e6511bb09e7mr9263507276.23.1742383642063; Wed, 19 Mar 2025 04:27:22 -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> In-Reply-To: Date: Wed, 19 Mar 2025 13:27:11 +0200 X-Gm-Features: AQ5f1JqQYOyqd9v0JnGhoEoNzZO4rb252lwHUmQu6BFNP6MQs_33bqM-7u3MoDo 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="0000000000000c42150630b04e3c" From: edmond.ht@gmail.com (Edmond Dantes) --0000000000000c42150630b04e3c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > You're cheating again - you've put an extra pair of brackets around one > expression and not the other, and assumed they'll work differently, but that's > not the grammar you proposed. > Why am I cheating? > spawn (getClosure()); This is an honest statement, provided that the second parentheses are optional. The full notation would be: > spawn (getClosure())(); > Instead you'd have to write this: > spawn (function() use(): string { return "string"; }); Exactly right, that's how it should be according to PHP syntax. Therefore, if we want to get rid of double parentheses, we need a separate rule for closures. I would name these two cases as follows: * spawn callable =E2=80=93 the general usage case * spawn closure =E2=80=93 the special case for closures I don't think these two rules make the language inconsistent because the `function` keyword allows separating the first expression from the second one. `spawn function` means that a `Closure` definition follows. Accordingly, there should be no additional parentheses `()` at the end. The reverse meaning is that if `spawn` is not followed by the `function` keyword, then it must be a valid expression that can be enclosed in parentheses. There are some doubts about whether all situations are correct, but so far, this is how it works for me: - call a standard PHP function ```php spawn file_get_contents('file1.txt'); ``` - call a user-defined function ```php function example(string $name): void { echo "Hello, $name!"; } spawn example('World'); ``` - call a static method ```php spawn Mailer::send($message); ``` - call a method of an object ```php $object =3D new Mailer(); spawn $object->send($message); ``` - self, static or parent keyword: ```php spawn self::send($message); spawn static::send($message); spawn parent::send($message); ``` - call `$class` method ```php $className =3D 'Mailer'; spawn $className::send($message); ``` - expression ```php // Use result of foo() spawn (foo())(); // Use foo as a closure spawn (foo(...))(); // Use ternary operator spawn ($option ? foo() : bar())(); ``` - call array dereference ```php $array =3D [fn() =3D> sleep(1)]; spawn $array[0](); ``` - new dereference ```php class Test { public function wait(): void { sleep(1); } } spawn new Test->wait(); ``` - call dereferenceable scalar: ```php spawn "sleep"(5); ``` - call short closure ```php spawn (fn() =3D> sleep(1))(); ``` > Sorry, what is exactly what we'd like to avoid? Syntax ambiguities. But it seems that avoiding them completely is impossible anyway because I've already found an old case where a property and a method are used in the same expression. --0000000000000c42150630b04e3c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>
>=C2=A0You're cheating again - you've put an extra pair of b= rackets around one
> expression and not the other, and assumed they'll work dif= ferently, but that's
> not the grammar you proposed.
>

Why am= I cheating? =C2=A0
> spawn (getClosure()); =C2=A0
This is an hone= st statement, provided that the second parentheses are optional. The full n= otation would be: =C2=A0
> spawn (getClosure())();

=
>=C2=A0= Instead you'd have to write this:=C2=A0
> spawn (function() use(): string { ret= urn "string"; });

Exactly right, that's how= it should be according to PHP syntax. =C2=A0
Therefore, if we want to g= et rid of double parentheses, we need a separate rule for closures.

I would name these two cases as follows: =C2=A0
* = spawn callable =E2=80=93 the general usage case =C2=A0
* spawn closure = =E2=80=93 the special case for closures=C2=A0=C2=A0

I don't think these two rules make the language inconsistent beca= use the `function` keyword allows separating the first expression from the = second one. =C2=A0

`spawn function` means that a `Closure` definitio= n follows. =C2=A0
Accordingly, there should be no additional parentheses= `()` at the end.=C2=A0=C2=A0

The reverse mean= ing is that if `spawn` is not followed by the `function` keyword, then it m= ust be a valid expression that can be enclosed in parentheses. =C2=A0
Th= ere are some doubts about whether all situations are correct, but so far, t= his is how it works for me:=C2=A0=C2=A0

- call= a standard PHP function

```php
spawn file_get_contents('file= 1.txt');
```

- call a user-defined function

```php
= function example(string $name): void {
=C2=A0 =C2=A0 echo "Hello, $= name!";
}

spawn example('World');
```

- ca= ll a static method

```php
spawn Mailer::send($message);
```
- call a method of an object

```php
$object =3D new Mailer()= ;
spawn $object->send($message);
```

- self, static or pare= nt keyword:

```php
spawn self::send($message);
spawn static::s= end($message);
spawn parent::send($message);
```

- call `$clas= s` method

```php
$className =3D 'Mailer';
spawn $class= Name::send($message);
```

- expression

```php
// Use re= sult of foo()
spawn (foo())();
// Use foo as a closure
spawn (foo(= ...))();
// Use ternary operator
spawn ($option ? foo() : bar())();```

- call array dereference

```php
$array =3D [fn() =3D= > sleep(1)];
spawn $array[0]();
```

- new dereference
```php
class Test {
=C2=A0 =C2=A0 public function wait(): void {=C2=A0 =C2=A0 =C2=A0 =C2=A0 sleep(1);
=C2=A0 =C2=A0 }
}

spawn= new Test->wait();
```

- call dereferenceable scalar:

`= ``php
spawn "sleep"(5);
```

- call short closure
=
```php
spawn (fn() =3D> sleep(1))();
```

<= div>>=C2=A0Sorry, = what is exactly what we'd like to avoid?

Syntax amb= iguities. =C2=A0
But it seems that avoiding them completely is impossibl= e anyway because=C2=A0
I've already found an old case where a= property and a method are used in the same expression.=C2=A0=C2=A0
--0000000000000c42150630b04e3c--