Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created December 7, 2018 11:36
Show Gist options
  • Select an option

  • Save nohwnd/04ab054de8ace2ceb0d3356d8099f00b to your computer and use it in GitHub Desktop.

Select an option

Save nohwnd/04ab054de8ace2ceb0d3356d8099f00b to your computer and use it in GitHub Desktop.
Prevent parent scope variables from leaking into function
# variable in parent scope
$a = 1
function f1 ($a) {
# $a is shadowed by the parameter result is --
"-$a-"
}
f1
function f1 {
# $a parameter was removed $a comes from
# parent scope, result is -1-
"-$a-"
}
f1
function f1 {
# $a parameter was removed so local $a is not
# defined
# result is --
"-$local:a-"
}
f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment