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

Why is the number 2 displayed?

Participant ,
Apr 18, 2008 Apr 18, 2008
Hi all,
I´m confused trying to work out why the code arg2 in hash signs displays the number 2? I can´t see a 2 anywhere- Is the fntest doing a len function? Thank-you very much
TOPICS
Getting started
516
Translate
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
LEGEND ,
Apr 18, 2008 Apr 18, 2008
Hydrowizard wrote:

<CFOUTPUT>#fnTest[1,2]#

[] Square brackets are for arrays.

() Parentheses are for parameters for a function.

Change that to: #fnTest(1,2)#

Unfortunately you just ran into a peril of a stateless language.

ColdFusion happily let you redefine the variable 'fnTest' from a
function to a two element, one dimension array without a bit of notice
or complaint.


Translate
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
LEGEND ,
Apr 18, 2008 Apr 18, 2008
Ian Skinner wrote:
>
> Unfortunately you just ran into a peril of a stateless language.

Loosely typed language.

This is not an issue with the stateless nature of HTTP requests and
responses, but rather that CFML is loosely typed and does not enforce
the typing of variables.

Translate
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
LEGEND ,
Apr 18, 2008 Apr 18, 2008
This line, #fntest[1,2]# called the function and the value of the 2nd argument is 2.
I didn't realize you could call a function with square brackets though.
Translate
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
Participant ,
Apr 19, 2008 Apr 19, 2008
but why is the value of the second argument 2? I just can´t see where!! The fntest second value? The cfargument is like a cfparam for functions vif i understand right- sorry just really confused thanks
Translate
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
Community Expert ,
Apr 20, 2008 Apr 20, 2008
<CFFUNCTION NAME="fnTest" OUTPUT="YES">
<CFARGUMENT NAME="arg1">
<CFARGUMENT NAME="arg2">
#arg2#
</CFFUNCTION>
<cfoutput>#fnTest[1,2]#</cfoutput>

This code produces an error, as it should. Coldfusion complains of an "Invalid CFML construct found on line 9 at column 20.". The offending line is the cfoutput line.

As Dan rightly hinted, you shouldn't call a function with square brackets, but with normal brackets, so: fnTest(1,2) or fnTest(arg1=3,arg2=5) or fnTest(arg2="myVar") ,..., and so on. The last example, where just one variable is passed, is possible because arguments are optional by default. However, we cannot do fnTest() because the function explicitly requires arg2.

Translate
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
LEGEND ,
Apr 18, 2008 Apr 18, 2008
<CFOUTPUT>#fnTest[1,2]#

is this how you call the function? why are those square brackets instead
of ( and )? where's the closing </CFOUTPUT>?

anyways, those look like a 1 and a 2 to me, but maybe not everyone can
see a 2 for a 2...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
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
Participant ,
Apr 19, 2008 Apr 19, 2008
why is the second argument value 2? Where is that defined?
Translate
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
LEGEND ,
Apr 19, 2008 Apr 19, 2008
Because it comes after the first comma.
Translate
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
LEGEND ,
Apr 20, 2008 Apr 20, 2008
> I can?t see a 2 anywhere

> <CFOUTPUT>#fnTest[1,2]#

What, even in the line of code I quote above? You can't see a "2" in that?

Let's stipulate that you've noted everyone else's advice and recoded that
to be valid:

#fnTest(1,2)#

You are passing "2" as the second argument into a function, which you've
instructed to be called "arg2". Then you output the value of "arg2". How
is it a mystery to you that when you set a variable to have a value of "2"
that when you output it, a "2" appears?

--
Adam
Translate
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
Participant ,
Apr 22, 2008 Apr 22, 2008
Thank you all for the replies, that makes sense now , cheers
Translate
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
Community Expert ,
Apr 22, 2008 Apr 22, 2008
LATEST
Hydrowizard, we all have those moments. I know I have.

Translate
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