latest reactions

David Levin
Does the trim still work if the form fie …
mal
as long as the join keys are same in eac …
Tarida
I am using ipinfodb.com to redirect the…
David Levin
Good stuff. For those interested in a UD …
PtcBux
oh Wilbur Gans wrote thank you so much…

Clicky Web Analytics
Use OpenDNS
ZERIGO DNS

Ultimate dns hosting based on pre-defined templates, DNS redirection and lot's more.

mxna feeds

ColdBox Platform Utilities v3.0 ReleasedColdFusion Education Initiative: New Web Application Development curriculum from AdobeColdFusion Job Opening - State College, PAAdobe ColdFusion e-seminar: REST Support in ColdFusion 10Experimenting With The Amazon Simple Storage Service (S3) API Using ColdFusionVideo : Community Week #1 - Multi user management in ColdFusion 10What's new in ColdFusion world at Scott on the RocksMy Adobe ColdFusion wishlistLooking for ColdFusion support in Brackets?ColdFusion Position In FLI want to see in ColdFusion 11?Have some Ramen with your ColdFusionSpeaking at Atlanta #ColdFusion User Group tonight on 2 important topicsScotch on the Rocks ColdFusion Conference – 1rst dayVideo : ColdFusion @ SOTR 2013

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

Visit Carlos GallupaMXNA webfeed

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 :-)

6450 viewed | 2 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  

Mark wrote.... (mail)

So why does this:

<cffunction name="onRequest" returntype="boolean">
<cfargument name="targetPage" type="string" required="true" />
<cfif isUserLoggedIn()>
<cfif not structKeyExists(session,"user")>
<!--- do something --->
<cfinclude template="test.cfm">
<cfelse>
<cfinclude template="#arguments.targetPage#">
</cfif>
</cfif>
<cfreturn true />
</cffunction>

behave so differently from this:

<cffunction name="onRequest" returntype="boolean">
<cfargument name="targetPage" type="string" required="true" />
<cfif isUserLoggedIn()>
<cfif not isDefined(session.user)>
<!--- do something --->
<cfinclude template="test.cfm">
<cfelse>
<cfinclude template="#arguments.targetPage#">
</cfif>
</cfif>
<cfreturn true />
</cffunction>

07 May 2009 3:04 cet  

Leave your comment

Your name


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


Some room for your reaction is placed here..



The answer to the ultimate question is?? (42 ;-))




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