Interesting Coldfusion Behavior
I wanted to test a PHP remote script today using CFHTTP method=GET. The remote script requires a few variables to be passed to it and well I wanted to initialize them using the cfparam tag.
The url variable is "dealer-locator-postcode" not even thinking about it I wrote the appropriate cfparam.
<cfparam name="url.dealer-locator-postcode" default="">
I got an error. I was like huh? why? Anyone?
Yeah thats right I just passed my Coldfusion 8 Certification and I didn't know this.
You can't have hyphens in coldfusion variables...but if I have a page called test.cfm and call it like so http://localhost/test.cfm?my-funky-variable=this works. And then dump the url scope out I get.

Ok WTF?!?
So how about this then?
<cfdump var="#url#>
<cfoutput>#url["my-funky-variable"]#</cfoutput>
<cfoutput>#url.my-funky-variable#</cfoutput>
Guess where the error occured? Yeah thats right the last statement choked and spat an nice error message out at me.
So what did I do then?
A complete hack!
<cfparam name="url['dealer-locator-postcode']" default="">
<cfparam name="url['dealer-locator-searchtype']" default="">
<cfparam name="url['dealer-locator-submit']" default="">
<cfhttp method="get" url="http://www.someStupidPHPSite/insomebloodycountry/index.php">
<cfhttpparam name="dealer-locator-postcode" type="url" value="#url['dealer-locator-postcode']#">
<cfhttpparam name="dealer-locator-searchtype" type="url" value="#url['dealer-locator-searchtype']#">
<cfhttpparam name="dealer-locator-submit" type="url" value="#url['dealer-locator-submit']#">
</cfhttp>
<cfoutput>
#cfhttp.fileContent#
</cfoutput>
As it turns out CF didn't barf. Mind you there is still something funky going on with the PHP script but it's a black box to me and will require probably hours of telephone tag.
Happy Coding...

Subscribe
Subscribe via RSS
Follow me on Twitter
Or, Receive daily updates via email.
Tags
adobe air ajax apple cf community cfml coldfusion examples ext flash flex google javascript max2007 max2008 misc open source programming railo software technology ui
Recent Entries
No recent entries.
Blogroll
An Architect's View
CFSilence
Rey Bango
TalkingTree

I'm not sure what your problem was here, nor what the solution was :-(
It's worth noting that "CF variables cannot contain -" is a slightly outdated concept: in CF, a struct key can be any value, and all variables are implemented as struct keys, so indeed one can call a variable anything one likes, eg:
<cfset variable["+-=##%!"] = "foo">
<cfdump var="#variables#">
One just needs to use associated array notation rather than dot notation.
--
Adam
The thing was it caught me off guard, I saw the php code getting the values from the url request scope so didnt' give it a second thought that url.my-variable wouldn't work. And naturally the first thing I did was dump
the url scope out and saw that CF correctly parsed it. I thought it was interesting in that I could pass a URL query param and NOT be able to access it in the way I was accustomed to, that being DOT notation, and I thought "interesting". So I looked up in the CF docs and didn't see any explicit mention that hyphens could NOT be used, only spaces couldn't be used for variable names.
1) Variable names must start with a letter, an underscore character, or a Unicode currency symbol. Examples of valid variable names are FirstName, _department, or $userID.
2) After the starting character, variable names can contain any number of letters, underscores, numbers, or Unicode currency symbols.
3)Variable names must not contain spaces.
4) Simple variable names must not contain the dot (.) character.
But upon reading it again...See point 2..."any number of letters, underscores, numbers or Unicode currency symbols"... no mention of other charcters. So yeah brain fart on my end...Having a blond moment, keep moving nothing to see here...