silverstripe/silverstripe-framework — pull request #2028 by simonwelsh (2013-05-29 10:28:53+00:00)
Title: FIX Prevent arguments passed to template methods from resetting the scope

The problem here is that ```$Blah.Foo($Baz)``` first calculates ```$Blah```, then ```$Baz``` and finally ```.Foo()```. So the scope is changed (by ```obj```), reset (by ```XML_Val```) then in the wrong place to call ```Foo```.

My solution is to clone the current scope for any arguments in the call, as well as in a with/loop opening block. This means the scope is correctly set for any chained calls as well as after the calls are executed (in the case of ```->pushScope()```).

I’m going to be moving the code that adds the clones into its own method (it’s duplicated in three places, just with a different variable) and add tests. Hopefully going to get it done tomorrow or Friday, which should hopefully be in time for RC1.