Skip to content

Add stateless closure cache - #23203

Closed
iluuu1994 wants to merge 2 commits into
php:masterfrom
iluuu1994:static-closure-cache
Closed

Add stateless closure cache#23203
iluuu1994 wants to merge 2 commits into
php:masterfrom
iluuu1994:static-closure-cache

Conversation

@iluuu1994

Copy link
Copy Markdown
Member

https://wiki.php.net/rfc/closure-optimizations#stateless_closure_caching

Extracted from #19941. Sadly, @DanielEScherzer discovered an edge-case I did not consider:

https://3v4l.org/uovSF#v8.5.9

class Foo {
    public function instanceCall() {
        return $this;
    }
    
    public function test($c) {
        return array_map($c, [1]);
    }
}

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

Here, the internal function array_map() can perform instance calls with just a named closure. Same with ['Foo', 'instanceCall']. That's quite esoteric, but this behavior should first be deprecated and removed before assuming it isn't being used.

So, for the time being, let's merge only the latter half of the RFC. Code bases with static properly annotated will still get the full performance benefit.

@iluuu1994 iluuu1994 closed this in f47cd21 Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant