Arrow Functions Import Variables By Values¶
Arrow functions automatically import the variables from the current context, to be used in its returned expression. It is still possible to assign a variable in such situation, by using an assignation in the return statement.
Yet, this does nothing, as the variable is imported by value, even when it is a reference in the first place. Hence, reading it access its value, but modifying it has no impact on the original context.
If the reference is important, the alternative is to use a closure, with a reference in the use(&$a) clause.
See Also¶
arrow-functions with references [Try me]