A little background: I'm working on a project converting a webapp in another scripting language into ColdFusion. One issue I'm having is that the old technology has some function names that are the same as functions in CF, but work slightly differently. Unfortunately, in most cases I need the old functionality, so I'm planning to write my own functions.
To cause the least pain in converting the code, I was planning to prefix each function with a character not usually used in function names, e.g., $val().
I know that $ and _ are valid in function names. Are any other characters I can use? I ask because I know that some frameworks out there use this convention and I don't want to run afoul of any of those in future development. Is it unreasonable to use multiple characters this way, e.g., $_val()?
Seems reasonable to me to use $_ as a prefix. Of course, you also might want to consider giving your functions a custom 'namespace', via either inclusion in a custom scope structure like 'UDF', yielding a function named like 'UDF.val()'; also, you could package them up together in a CFC, and access them as component methods. Either way, you would be safe from name conflicts.
edit
To test the comment you just made regarding custom functions with the same name as the built-in function, I made a little test to see if that's true. It appears that you actually can build functions with the same name as the built in ones, if they are within a custom scope:
<cffunction name="foo">
<cfreturn "bar">
</cffunction>
<cfset udf = {}>
<cfset udf.IsDefined = foo>
<cfoutput>#udf.IsDefined()#</cfoutput>
This code outputs "bar".
Or, if you like the CFC approach:
foo.cfc
component {
function IsDefined()
{
return "blah";
}
}
And the invoking code:
<cfset udf2 = createObject("component", "foo")>
<cfoutput>#udf2.isDefined()#</cfoutput>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With