• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

isValid("string" vs <cfparam type="string"

Engaged ,
Dec 17, 2006 Dec 17, 2006

Copy link to clipboard

Copied

Just a quick note regarding a difference between isValid and <cfparam, to hopefully help others down the line...
(pay attention to line 5 - it is the difference between the two)

Example #1:

<cfset foo.test = "" />
<cfset bar = queryNew("test") />
<cfset queryAddRow(bar, 1) />
<cfset querySetCell(bar, "test", "bla") />
<cfset foo.test = bar['test'] />
<cfoutput>#isValid("string", foo.test)#</cfoutput>
<cfparam name="foo.test" type="string" />

In example #1, the isValid("string", ...) function does not throw an error, but the <cfparam type="string"... does.

Example #2:

<cfset foo.test = "" />
<cfset bar = queryNew("test") />
<cfset queryAddRow(bar, 1) />
<cfset querySetCell(bar, "test", "bla") />
<cfset foo.test = bar['test'][1] />
<cfoutput>#isValid("string", foo.test)#</cfoutput>
<cfparam name="foo.test" type="string" />

In example #2, no error is thrown.

As I mentioned, the difference is...
Line #5 in 1st example: <cfset foo.test = bar['test'] />
Line #5 in 2nd example: <cfset foo.test = bar['test'][1] />

If you do not specify the query row number, when accessing a query variable using array notation, isValid() may not throw an error, however <cfparam> might throw an error.

Just an interesting observation.

-Aaron Neff

Views

285

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 15, 2007 Sep 15, 2007

Copy link to clipboard

Copied

LATEST
To clarify... If the query row is omitted from the indexed/array notation, then isValid() and <cfparam /> produce different results.

In the attached code example below, the query row was omitted intentionally to illustrate.

Two possible solutions are:

1) Make isValid() throw an error (so that they both throw an error)
2) Make <cfparam /> not throw an error (so that they both do not throw an error)

I feel the behavior should be consistent. Does anyone feel otherwise? If the behavior should be consistent, then which solution, or other solution, is preferred?

Let's discuss!

Thanks,
-Aaron
---------

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation