-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Allow to change default variable scope #12199
Comments
That is the purpose of declaring your variables with scope, .e.g, |
Correct. I believe the request is to have a way in the script to set such a scope to be the default for all variables in that scope, so that when creating an unscoped variable it is automatically assigned the |
Yes, exactly. When you have very long scripts, it's very ugly to prefix all variables with |
PowerShell's dynamic scoping is a problem in other areas too, notably with not wanting For more robust code, lexically scoped variables, or their emulation with the Conceivably, a new |
Not a bad suggestion, @mklement0. For myself, I was imagining introducing a preference variable; e.g., |
The problem with preference variables is again their dynamic scoping - child scopes that weren't written with all-private variables in mind could break. I suggested I suppose something like |
This isn't answered yet |
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
@iSazonov What is the answered resolution ? |
@fabienfl-orc PowerShell is well-designed language for scripting. :-) Later classes was introduced in PowerShell to address "programming" scenarios. |
Currently, the default variable scope allows variables to be accessed in child scopes.
I always had a lot of problems with this in bigger scripts.
It would be nice to have an option, e.g. at the beginning of a script, which tells PS
that the default scope should be private for this script.
The text was updated successfully, but these errors were encountered: