Hi everyone

On 13.03.26 15:58, Ilija Tovilo wrote:
On Fri, Feb 27, 2026 at 2:47 PM Ilija Tovilo <[email protected]> wrote:
RFC: https://wiki.php.net/rfc/closure-optimizations

The vote will end on 2026-03-13 14:00 UTC.
The vote has now closed. The RFC was accepted with 24 Yes, 0 No and 1
Abstain votes.
Thank you for participating.

A very late update on this RFC. Sadly, some edge cases were discovered with regards to static closure inference.

Consider:

    class Foo {
        public function instanceCall() {
            return $this;
        }

        public function test($c) {
            return (function () use ($c) {
                return array_map($c, [1]);
            })();
        }
    }

    $foo = new Foo();
    var_dump($foo->test('Foo::instanceCall'));

    // array(1) {
    //   [0]=>
    //   object(Foo)#1 (0) {
    //   }
    // }

The closure within test() violates none of the rules from https://wiki.php.net/rfc/closure-optimizations#static_closure_inference, yet performs an instance call. I failed to consider this case, and sadly this is not easy to detect via a new rule. For this reason, I have decided to omit static closure inference from the implementation and only merge the stateless closure cache. Code with all relevant functions properly annotated as static will get the full performance benefit.

The RFC was updated accordingly. See https://wiki.php.net/rfc/closure-optimizations#errata.

If you have any objections to this partial implementation, let me know.

Ilija

Reply via email to