Re: [VOTE] True Async RFC 1.6

From: Date: Sat, 22 Nov 2025 12:37:11 +0000
Subject: Re: [VOTE] True Async RFC 1.6
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  Groups: php.internals 
Request: Send a blank email to internals+get-129391@lists.php.net to get a copy of this message
> basically in $result = foo(spawn(bar(baz(file_get_contents())))); file_get_contents() receives > outside context from spawn() to turn into async mode. > Also foo(), bar(), baz() can be in different namespaces, different classes, so by looking at > the code calling file_get_contents(), it's not clear if the result is sync or async. Ok, then let’s look in detail at what is happening. > foo(spawn(bar(baz(file_get_contents())))) i.e. ```php $result = foo(spawn(bar(...), fn () => baz(file_get_contents()))); ``` Did I understand the code correctly? (Assume there was also some parameter there, like a file name.) 1. We call bar in a separate coroutine, which 2. First calls file_get_contents 3. Then passes the result to the function baz() Is that correct? > Also foo(), bar(), baz() can be in different namespaces, different classes, so by looking at > the code calling file_get_contents(), it's not clear if the result is sync or async. If we are discussing the code above, then it returns a Promise not of the file-reading result. This is a completely different logic, and here the programmer clearly intended to do something else. What if the function baz replaces every a character with baz? It's ok. ```php $foo = file_get_contents('foo.txt'); // sync $result = spawn($foo); // error because $foo is string ``` Here I don’t understand why someone would intentionally write incorrect code. Code: ```php $result = foo(file_get_contents('foo.txt')); // equivalent to // the code below has no practical purpose $result = foo(await(spawn(file_get_contents(...), 'foo.txt'))); ``` Is that correct?

« previous php.internals (#129391) next »