Re: [VOTE] True Async RFC 1.6

From: Date: Mon, 24 Nov 2025 08:36:36 +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 17  Groups: php.internals 
Request: Send a blank email to internals+get-129424@lists.php.net to get a copy of this message
Hello.

> I think there's a lot of confusion in this thread because different people are talking
> about different scenarios. Perhaps it would be useful to introduce some User Stories

Yesterday I briefly reviewed the WordPress code to estimate the
refactoring effort.
The amount of global state accessed through global and static is
quite large.
However, it seems technically possible to switch global and static
variables per coroutine.
I’m not sure how this will affect performance (maybe 1–2% on
switches?), but the task looks realistic.

At first I thought this was a bad approach, because if such a feature
were added to PHP,
everyone would start using global as a way to exchange data inside a
coroutine. However, this situation can be viewed from a completely
different perspective:

```php
function myFunction(): void {
    global $x;
}

// This code is equivalent to:
function myFunction(): void {
    effect ?string $x = null; // <-- function effect, external dependency
}

// This code is equivalent to:
function myFunction(): void in ?string $x {

}

// Then calling the function:
with ($x = "string") {
    myFunction();
}
```

In other words, this is a function effect that turns previously
unmanaged and unsafe code into a function with an explicit
external-dependency contract.
And in the future, it could be improved by adding proper effect
support to the language. It turns out that a feature previously seen
as an antipattern can actually be framed as a modern concept from
functional programming.

Of course, these statements need to be validated with code and testing,
and they also require a separate RFC.


Thread (106 messages)

« previous php.internals (#129424) next »