Setting to merge argument and local scope

What do you think about having a setting in Lucee to merge local and argument scope, that would mean that Lucee would not have separate scope for local and argument, argument would be simply an alias for local.

  • because the distinction between this 2 scopes, not really has a a benefit
  • performance

this means you would no longer have to scope arguments for best performance!

this would also be an option per CFC? I’d love to also have the localmode=true per CFC

Yes, that is the main reason to do this, we improve performance with this, but also simplify the language. Having 2 local scopes for a function is to much, same as with the component (variables and this).

The reason we do not support this so far is code injection, when you inject a function into a cfc that has set this flag, it will change the behaviour of the function and i can happen that you are not aware if a cfc has that flag when you inject a function. Also will that fag be extended to sub components? I had the feeling this opens pandoras box, so i did not add it.

I reckon let us shoot ourselves in the foot if we want to!
i.e. localmode=false is the default, which can cause it’s own problems
having to add localmode=true to every function is just ugly

back to the topic about local and arguments.

so the arguments scope will still exist, then if you update something directly in arguments scope, the local scope will then be out of sync and you will have to reference the arguments scope directly?

Is this suggestion something that would work with all legacy code that uses both and or would it require code to be refactored to remove references to one scope?

How would Lucee behave for this code:;;
echo( ); // outputs??
echo( ); // outputs??

What about this code?

var myStr = {
  "some" : "data"
function myFunc() {
  var brad = 'wood';
  return arguments;
// Pass struct by reference
myStr = myFync( argumentCollection=arguments );

What would myStr contain at that point? Would the local brad variable from the UDF be part of myStr now from the time it was the arguments scope?

1 Like

the arguments scope simply will point to the local scope

it would output:


arguments simply will not exists as a separate scope, it will simply point to the local scope.
But one thing will not change of course, the local scope will still get populated with the arguments (as the argument scope is populated today). Local and argument scope are not simple structs and when you do argumentcollection, you never pass in that scope one to one.

Understood. I think there’s some potential for backwards compat, but it makes sense. I would push for this to be at the CFC level however. server-wide settings are difficult to use with frameworks and 3rd party code and typically don’t get used.