Skip to content

Conversation

@KorvinSzanto
Copy link
Contributor

@KorvinSzanto KorvinSzanto commented Dec 8, 2025

This change ensures scopes don't remain set against transformers for longer than they need to be.

There were a few different options I considered:

  1. Unsetting the scope after finishing transform (This is what I chose)
  2. Using a \WeakReference on the transformer rather than referencing the scope directly
  3. Removing the ->setCurrentScope entirely and using \Reflection(Function|Method) to determine how and when to pass the Scope to transform calls
Option Prevents Leaks Backwards compatible Doesn't impact performance Ideal DX
Unsetting [1]
`\WeakReference [2]
\Reflection [3]
  • [1]: This change makes it so that you can't access the current scope after transform has completed. Instead the author of the transformer needs to manually capture the scope themselves using ->getCurrentScope() during the transform if they need to have the scope available so late.
  • [2]: The only impact is that Transformer authors would no longer be able to access $this->currentScope, which isn't really a huge deal given that we already have ->getCurrentScope() available, but it is a BC break.
  • [3]: While the impact is minimal, there is certainly an impact to using reflection for every single ->transform / ->include... call.

Replaces #563, #569

@KorvinSzanto KorvinSzanto merged commit 9e81735 into master Dec 8, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants