Param (
[Parameter(Mandatory=$true)]
[string[]] $t
)
Function test {
$empty = @()
$t += $empty
Write-Host $t
}
test
should append input arguments with empty array
assigns empty array instead of appending the empty array
PSVersion 5.1.18362.145
You're implicitly creating a _function-local_ $t variable inside your test function, which goes out of scope when the function is exited - the _script-level_ $t is never modified.
In an _assignment_, you'd have to refer to the script-level $t variable as $script:t, for instance.
(However, on _retrieval_ of the script-level $t value, $t is sufficient (unless you're shadowing it with a local $t). This asymmetry is a common pitfall - see this StackOverflow answer for details.)
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.
Most helpful comment
You're implicitly creating a _function-local_
$tvariable inside yourtestfunction, which goes out of scope when the function is exited - the _script-level_$tis never modified.In an _assignment_, you'd have to refer to the script-level
$tvariable as$script:t, for instance.(However, on _retrieval_ of the script-level
$tvalue,$tis sufficient (unless you're shadowing it with a local$t). This asymmetry is a common pitfall - see this StackOverflow answer for details.)