Revert passing script variables by reference #16030
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does it do?
#15578 added the EXTR_REFS flag to the extract() function in modScript::process with the intention of allowing plugins to manipulated variables passed in to it.
This PR reverts that back to how it was in 2.x.
Why is it needed?
Unfortunately per https://community.modx.com/t/spform-how-to-change-language/4917/16 the pass by reference is causing issues when local variables in a snippet share the name of a script property or a copy of $scriptProperties is made. This is causing wildly unexpected results.
How to test
Two very simple snippets to reproduce the behavior are provided in the forum, both assuming the snippet is called with
[[!mySnippet? &my_prop=`A`]]
:The expected result, because there is no explicit change made to $scriptProperties, is
A
. However both returnB
.It also goes the other way, though this type of code would be less common:
Related issue(s)/PR(s)
https://community.modx.com/t/spform-how-to-change-language/4917/15
#15578