OK, here are some technical questions. Consider the following code:

    <cffunction name="method" returntype="string">
        <cfargument name="arg1" type="String">  
        <cfset arg1 = encrypt(arg1, "x")>
        <cfset arg2 = encrypt(arg1, "x")>
        <cfreturn arg1>
    </cffunction>

Questions are:

  1. In which scope is arg1 created by CFSET?
       (a) function local scope
       (b) variables scope
       (c) neither, it overwrites arguments.arg1

  2. In which scope is arg2 created by CFSET?
       (a) function local scope
       (b) variables scope
       (c) neither, it overwrites arguments.arg1

  3. What value is returned by this function?
       (a) the original value of arg1 as passed into the function
       (b) the encrypted value of arg1

The answers on CFMX 6.1 are: 1(a), 2(b), and 3(b). Isn't this odd? Since the
CFSET doesn't use the "var" keyword, shouldn't arg1 be created in the
variables scope (as arg2 is), not the local scope?

And, since arguments scope takes precedence over variables scope when
searching for unscoped variables, shouldn't answer 3(a) be correct (if we
agree that arg1 should be created in the variables scope)?

Now for a bonus question. Consider the following code:

    <cffunction name="method" returntype="string">
        <cfargument name="arg1" type="String">  
        <cfset var arg1 = encrypt(arg1, "x")>
        <cfreturn arg1>
    </cffunction>

Here's the question:

  4. In which scope is arg1 created by CFSET?
       (a) function local scope
       (b) variables scope
       (c) neither, it throws an exception

The answer is: 4(c). But if it's illegal to explicitly create a variable in
the local scope that has the same name as an argument, then why does CFMX do
it implicitly in the first code example?

Is this behavior deliberate? Is it a side-effect? Is it a bug?

Vince







----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to