> So what would happen in the following in code?
> <cfoutput>#structKeyExists(remote_host,'blah')#</cfoutput>

CF would lookup up remote_host and find it in CGI scope. It would then
pass the value of CGI.remote_host to structKeyExists().

> Does it need to go off to the web connector, or does it already know that
> the CGI scope can't contain a struct?

I don't know whether CGI.remote_host causes a web connector lookup -
probably not since that's a 'standard' CGI variable. Whether it can be
a struct or not is irrelevant at that point. The sequence is:
- CF evaluates the _expression_ which is the first argument
- CF evaluates the _expression_ which is the second argument
- CF calls structKeyExists() and passes those values
- structKeyExists() checks the first arg is a struct and then looks
for the key specified by the second argument

> <cfoutput>#structKeyExists(foo,'bar')#</cfoutput>
> If foo doesn't exist in the variables scope, structKeyExists() definitely
> looks in the form scope, and presumably the other implicit scopes.

No, structKeyExists() does *not* look in those scopes - CF does.
structKeyExists() only gets executed once CF has evaluated the
_expression_ foo and retrieved whatever value it has (or not).

> What is the performance benefit of using structKeyExists() in that scenario?

Because CF looks up foo and then structKeyExists() only checks the
value of foo for a key called bar.

isDefined('foo.bar') by constrast will perform all sorts of searches -
if it finds a foo but that doesn't contain bar it will look for a
variable called foo.bar and start the search all over again.

Do <cfset variables['foo.bar'] = 42 /> and then try
isDefined('foo.bar') vs structKeyExists(foo,'bar') (the latter will
fail *before* calling structKeyExists() because foo is not defined as
a variable).
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to