Accessibility

TechNote

Multiple Variable Assignments and Local Scope

Issue


In the code given below multiple variable assignment is done in var (local scope) but when variables scope is dumped you can see the second and third variables which are in var scope which is wrong.

 

<cfscript>

    Any function test() {

        value = "Tom";

        var hero=villian=comedian=value;

        return hero;

    }

</cfscript>

<cfoutput>#test()#</cfoutput>

<cfdump var="#variables#">

 

Reason


When a multiple variable assignment is done it considers only the first one in local scope and not the others.

Solution


Here the villan and comedian can be seen in variables scope.  Instead, declare and assign each variable individually using var.

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:cpsid_51738

Products Affected:

coldfusion