scoping bug? (pass by value, udfparms)

Microsoft Visual FoxPro - Programmer Exchange

A variable declared LOCAL and passed by value to a procedure can get changed 
in that procedure. This seems to me like a potentially serious bug. Either 
that or I'm making a mistake somewhere.

Here's a demo (assume a database is open):

LOCAL myvar

myvar = "foo"
DO HOME() + "tools\gendbc\gendbc" WITH m.myvar, .T.
? m.myvar    && myvar = "foo.PRG"!!

myvar is local! That should not happen!

(myvar is out of scope within gendbc as expected.)

It is possible to work around this by explicitly forcing a pass by 

myvar = "foo"
DO HOME() + "tools\gendbc\gendbc" WITH (m.myvar), .T.
? m.myvar  && myvar = "foo" as expected

But I should not have to do that. Am I misunderstanding something?

Hi Paul,

The SET UDFPARMS has affect on UDFs calls only.
In a procedure call with DO statement parameters are always passed by 
reference, unless they are enclosed in parentheses.

I covered it in detail in my article *Difference between FUNCTION and 
PROCEDURE statements* at
Wow, I did not know that. Thank you for informing me.

Interesting site you have there. I want to look around it some more.