[thelist] CF: Attributes to Locals?

Raymond Camden jedimaster at macromedia.com
Fri Sep 14 07:20:38 CDT 2001


> I will often do something like this:
> 
> <cfparam name="Attributes.MyVar" default="">
> <cfset MyVar="Attributes.MyVar">
> 
> I do this simply to keep my code a little tidier, but this in itself 
> becomes somewhat cumbersome. I'm sure there's a better way. How would 
> you handle this?

I assume you really mean, <CFSET MyVar = Attributes.MyVar>, ie, without
the quotes.

Um, there is nothing wrong with this. I don't do it, but in theory, it
adds only .0000001 ms to your execution time, so if this makes your code
easier to read for you and your team, I say go for it.

If you want altnatives, you can also do this, which would make all the
copies at once...

<CFLOOP ITEM="Key" COLLECTION="#Attributes#">
	<CFSET "#Key#" = Attributes[Key]>
</CFLOOP>

This assumes, however, that your attribute names are all proper
variables names, which may not be true.

-Ray





More information about the thelist mailing list