Subsribe to our RSS

latest reactions

Ismail
Genius! …
Daryl James
Wow, great post, I never realized there…
Brad
Wow, thanks for posting this.Strangely …
jax
Ted must be a php fan...Most Ted's ar …
pagla
wow. thanx a lot …

Use OpenDNS

mxna feeds

Starting ColdFusion on Boot with UbuntuNew CF/Lucene Project - GOATBolt - The New ColdFusion IDEBolt - The New ColdFusion IDESecurity Update for ColdFusion 8Stop / Start / Restart ColdFusion on Mac OS X LeopardMS SQL Server 2008 breaks lots of applications"Iterating Business Objects - Who Needs Them?", with Peter BellUsing Application-Specific Mappings With ColdBoxConsulting workIntegrating PayPal Payments Into Your Site with ColdFusion: Part 4Take the CF Jeopardy challengeAdobe MAX 2008 BoF: Addressing the ColdFusion Developers' Skills GapTransient Creation Performance - ColdSpring and TransientFactoryForgot to import your ColdFusion tag libraries?

All files are strictly confidential: all information is classified.
© Copyright 2002 - 2008 mximize.com.
All right reserved.

MXNA webfeed

Visit Carlos GallupaPowered by ColdFusion MX

StructKeyExists(scope,'var') instead of isDefined()

Just came across some articles that explained the following, if you use ColdFusion MX it's better to check for a variable in their own scope structure than checking the variable with isDefined(). Why you ask... this is why... An isDefined() checks all the scopes for a particular variable even when you say isDefined("session.var"). This will still look in other scopes than the session scope.

In MX all the variables are structures and you can check if a variable is in a particular scope with StructKeyExists(scope,"var")

When checking for a variable it is therefore better to use StructKeyExists() because ColdFusion will only look in the given scope for the variable.

NOTE: Do not use the structKeyExists() with CFC's because the URL scope does not exist in a CFC, when not using URL parameters in your CFC you are good to go :-)

1384 viewed | 1 opinion(s)  | del.icio.us | Digg it | Tjarko @ 11/08/04 0:00 cet


Reactions:

joe coder wrote.... (site)

I came across your post from a Google search results. It needs a correction.

You stated "NOTE: Do not use the structKeyExists() with CFC's because the URL scope does not exist in a CFC, when not using URL parameters in your CFC you are good to go :-)". -- Which is correct *most* of the time.

However, when you have a CFC that is "REMOTE", er, rather, 'access="remote"', the URL *does* exist and is usable.

This is particularly important and useful for ajax functionality (that's the only place I use it - where it's more hidden) when a request is made to, say, "http://www.yoursite.com/cfcname.cfc?method=functionname&URLvar1=x&URLvar2=y", you can access the URL scope inside the CFC successfully.

22 July 2008 18:41 cet  

Leave your comment

Your name


Your url/website/link/email....


Some room for your reaction is placed here..



A dozen apples are how many?? (12 would be a good answer for this)




URL en mail addresses are translated for you... life sometimes is that simple!!