Created
December 7, 2018 11:36
-
-
Save nohwnd/04ab054de8ace2ceb0d3356d8099f00b to your computer and use it in GitHub Desktop.
Prevent parent scope variables from leaking into function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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