On Wednesday, Apr 2, 2003, at 06:34 US/Pacific, Howard Fore wrote:
Adding the structKeyExists call won't change a whit as the keys are added to the struct by the cfargument tag. I really wish that wasn't the case...
I'm puzzled by this comment - as the code I posted showed, structKeyExists() returns false unless the argument is actually passed in.
The deciding factor seems to be whether or not you have a default value set for the CFARGUMENT. For example:
foo.cfc:
<cfcomponent displayname="foo">
<cffunction name="bar" output="false">
<cfargument name="arg1" type="string">
<cfargument name="arg2" type="string">
<cfargument name="arg3" type="string" default="Ni!">
<cfset myData = structNew()>
<cfset myData.arguments = structCopy(arguments)>
<cfset myData.arg1Exists = structKeyExists(arguments,"arg1")>
<cfset myData.arg2Exists = structKeyExists(arguments,"arg2")>
<cfset myData.arg3Exists = structKeyExists(arguments,"arg3")>
<cfreturn myData>
</cffunction>
</cfcomponent>
cfcTest.cfm:
<cfinvoke
component = "foo"
method = "bar"
returnVariable = "fooData">
<cfinvokeargument
name="arg1"
value="MR2DX">
</cfinvoke>
<html>
<head>
<title>CFC Test</title>
</head>
<body>
<cfoutput>
<CFDUMP var="#fooData#">
</cfoutput>
</body>
</html>
This yields:
ARG1EXISTS YES
ARG2EXISTS NO
ARG3EXISTS YES
ARGUMENTS struct
ARG1 MR2DX
ARG2 [undefined struct element]
ARG3 Ni!
As you can see, it isn't the mere existence of the CFARGUMENT that adds it to the arguments struct, it is the assignation of a default value.
The workaround here is to not use the default attribute unless you want to set a non-empty value. However it seems to me that the current behavior is messy. A function parameter that is empty is vastly different from one that is undefined altogether (null != empty).
--
Howard Fore, [EMAIL PROTECTED]
"The streets are safe in Philadelphia. It's only the people who make them unsafe." - Frank Rizzo, Philadelphia's former police chief, mayor and city CEO
