View comments | RSS feed

ParameterExists

Description

This function is deprecated. Do not use it in new applications. Use the IsDefined function.

Determines whether a parameter exists. ColdFusion does not evaluate the argument.

History

New in ColdFusion MX: This function is deprecated. Do not use it in new applications. It might not work, and might cause an error, in later releases.

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


bruceschuman said on Jun 10, 2002 at 7:27 PM :
Just logged in here, trying to find something on "ParameterExists". Either there are no comments, and this is the first, or they are a little hard to find....

:)

In any case, my ISP is telling me he is hot to move to CF MX. However, I have 25,000 pages of CF code (or more) that are extensively based on "ParameterExists". And, as far as I can tell -- MX doesn't like ParameterExists, and wants to insist on "IsDefined". I'm getting all kinds of weird errors -- not the least of which is that his MX server and the "free download" of CF 6.0 don't read identical pages the same way.

But for me, in my clumsey little way, these functions don't seem interchangeable. ParameterExists is clearly and easily a 2-state function.

I'll have a block of code that runs inside a <CFIF #ParameterExists(somevariable)# is "Yes"> codeblock </CFIF>

and then maybe another block that runs inside <CFIF #ParameterExists(somevariable)# is "No"> codeblock
</CFIF>

I could perhaps use a format like

<CFIF IsDefined(somevariable)>Block 1<CFELSE>Block 2</CFIF>

But what do I do if all I am interested in is the negative state -- <CFIF #ParameterExists(somevariable)# is "No">

There is no negative version of IsDefined. So, maybe I would have to write this function

<CFIF IsDefined(somevariable)>
(blank)
<CFELSE>
What I really want to say
</CFIF>

I must be missing something obvious. IsDefined is supposed to be more elegant. But I have a gazillion blocks of code that are controlled by ParameterExists, and I don't see any way -- at least yet -- of rewriting all those pages to accommodate this change.

Oh well, now what.

:)

- Bruce

PS, as regards these below rating buttons/options -- I could not find any discussion of this subject. Either this is brand new, or it is hard to find. Thanks. I guess I'll stick with "no opinion" for now.





sgilson102 said on Jun 18, 2002 at 9:00 AM :
ParameterExists should still work as usual in CF MX.

Stephen M. Gilson
CF Doc Manager
aeverett said on Aug 2, 2002 at 2:27 PM :
Easy:

<cfif NOT IsDefined("foo")>

</cfif>
KirkR said on Nov 17, 2003 at 6:40 AM :
I just wanted to confirm that the following does work, and to document the proper code, (where Event is a passed variable.)

<cfif IsDefined("Event")>
Yes...
<cfelseif NOT IsDefined("Event")>
No...
</cfif>
josvanhetcrossbos said on Aug 13, 2004 at 7:00 AM :
I'm having problems about the following:

<cfif IsDefined(Session.LoggedIn)>
is NOT the same as
<cfif ParameterExists(Session.LoggedIn)>

Is that because I evaluate a Session-variable? It works with the ParameterExist-function, but it won't with IsDefined, so don't deprecate ParameterExists please.
halL said on Aug 17, 2004 at 2:19 PM :
To test whether a variable exists using IsDefined, put the variable name in quotation marks.
To test whether a variable exists using ParameterExists, DO NOT put the variable name in quotation marks.

The following two tests are equivalent:
ParameterExists(Session.foo)
IsDefined("Session.foo")

Unlike with most ColdFusion functions, ColdFusion does not evaluate the parameter in the ParameterExists function.
Like with most ColdFusion functions, ColdFusion does evaluate the parameter in the IsDefined function.
Therefore, In IsDefined, if you do not surround the variable name in quotes, ColdFusion uses the value of the variable as the parameter, which is not what you want in this case.
This behavior lets you test whether a variable's value is the name of another variable.
Also, please note that ParameterExists is deprecated.
csecord said on Oct 30, 2004 at 9:36 AM :
<i>This behavior lets you test whether a variable's value is the name of another variable.</i>

I've been programming for 10 years and I have never needed to know if the value of parameter A is itself a parameter. That is a totally useless function.

IsDefined should work like every other function (and specifically, just like parameterexists used to) and test the value passed to it. Code like this: if (isdefined("foo") and isnumeric(foo)) just looks like a syntax error. That's valid code, but when foo is in quotes in the first function and not in quotes in the second function, it just looks wrong.

In that once in a lifetime situation where I need to know if the value of parameter A is itself a variable, I'll just use evaluate. Otherwise, isdefined is an odd function that behaves in a different way than any other function and I personally think it's implementation constitues poor design.

At any rate, there are a million lines of coldfusion code out there and macromedia can't force its customers to rewrite them (unless they want to lose those customers) so parameterexists() will always continue to work.
JordanReiter said on Aug 2, 2005 at 2:14 PM :
csecord said "I've been programming for 10 years and I have never needed to know if the value of parameter A is itself a parameter. That is a totally useless function."

Really? I've been programming for a while and I think it's *very* useful. Suppose you have a dynamically generated form like this:

[cfloop query="People"]
[p]
Person ###CurrentRow#:
Name: [input type="text" size="30" name="name_#personID#" value="#name#" /]
[input type="hidden" name="record_list" value="#personID#" />
[input type="checkbox" [cfif approved is true]checked="checked"[/cfif] value="true" name="approved_#personID#" /] Approved
[/p]
[/cfloop]

(I'm using brackets because I'm not sure what happens to tags).

On the page that processes the form, you'd want to check whether or not a checkbox was checked. If it wasn't checked, it wasn't defined.

[cfloop list="#record_list#]" index="this_record"]
[cfif isDefined("approved_#this_record#")]
...
[/cfif]
[/cfloop]

There is no way to implement this kind of functionality without having isDefined evaluate the expression in parentheses.
JordanReiter said on Aug 2, 2005 at 2:28 PM :
Replacing those ParameterExists is easy.

For those of you with large sections of code using ParameterExists, I believe the following RegEx should work with most global search and replace tools:

Find:
[#]?ParameterExists\(([^)]+)\)[#]?

Replace with:
IsDefined(" ")

You can even do this with a recursive CF script using CFDIRECTORY and CFFILE. (This is left as an exercise for the reader).

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt249.htm