Re: PHP True Async RFC - Stage 2

From: Date: Wed, 19 Mar 2025 11:51:03 +0000
Subject: Re: PHP True Async RFC - Stage 2
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
>
>  Generally, RFCs are for changes in the language itself, not for API
contracts in C. That can generally be handled in PRs, if I understand
correctly.
>

I thought this was handled by PHP INTERNAL.
So I have no idea how it actually works.

>
>  or other weird shenanigans? I think it would be better as a statement.
>
Your example was absolutely convincing.
I have nothing to argue with :)
So, suspend is 100% an operator.

>
>  What happens if it throws? Why does it return NULL; why not void or
the result of the awaited spawn?
>
Exceptions are thrown if they exist. This also applies to suspend, by the
way.

Why not void?
Because the expression $result = await ... must resolve to something.

If I remember the core code correctly, the PHP engine returns NULL even
if the function is declared as void.

>
>  Wouldn't it be better to throw an exception instead of silently failing?
>
Possibly, yes.
For me, this is a difficult situation because the code inside the final
handler is already executing in a context where any exception can interrupt
it.

>
>  Hmm. Do you mean this literally? So if I call a random function via
spawn, it will have access to my current scope?
>
Exactly.
And yes, accessing a Scope defined in a different context is like
shooting yourself in the foot.
That's why this possibility should be removed.

>
>  I know I have been critical in this email, but I actually like it; for
the most part. I think there are still some rough edges to sand down and
polish, but it is on the right track!
>

In this RFC, I made two very big mistakes due to attention distortion.
This once again proves that it should be moved forward very slowly, as it
only seems simple.

The first major mistake was that I tried to make functions an element of
structural concurrency.
But to do so, functions would need to have an async attribute, which
contradicts the RFC.

The second mistake is the currentScope() function, which doesn't just
shoot you in the foot—it shoots you straight in the head (just like
globalScope()).
Of course, a programmer can intentionally pass the $scope object to
another coroutine, but making it easier for them to do so is madness.


Thread (59 messages)

« previous php.internals (#126839) next »