4 ms·
~3% performance gains. I didn’t understood part about $this.
by hyperionultra 6mo ago
~3% performance gains. I didn’t understood part about $this.
- rererereferred 6mo agoIf the closure doesn't use $this (an instance of the current class) then it doesn't need to store a reference to it, which also skips the bookkeeping from the garbage collector.
- ethan_smith 6mo agoIn PHP, closures defined inside a class method automatically capture `$this`, which means the closure holds a reference to the entire object even if it never uses it. This prevents the object from being garbage collected and adds overhead. The optimization detects when `$this` isn't actually used and makes the closure static automatically, dropping that unnecessary reference.