The fact that stupidity is well-documented doesn't make it any less stupid.
I don't think it's stupid so much as an exception to otherwise common rules. That's... awkward. And awkwardness cascades through a system such that all code becomes as awkward as the most awkward bit of the system.
Is it even possible in any other circumstance to create such a structure/array with undefined elements? I had assumed no, and coded many a function with that assumption. It's no good to argue that this quirk is confined to the arguments struct/array, because if you modify Adam's function to simply return arguments, the quirky elements are retained.
<cffunction name="func2" output="false" returntype="struct"> <cfargument name="arg" required="no" /> <cfreturn arguments /> </cffunction>
<cfscript> CFC = CreateObject("component", "test"); foo = CFC.func2(); </cfscript> <cfdump var="#foo#" label="f2 return" /> <cfoutput> #ArrayLen(foo)#, #StructKeyList(foo)#, #StructKeyExists(foo,"arg")#, #IsDefined("foo.arg")# </cfoutput> <cfif foo.arg>foo.arg exists</cfif>
...results in:
f2 return - struct ARG [undefined struct element] 1, ARG, NO, NO
Error Occurred While Processing Request Element ARG is undefined in FOO.
Thus, this quirky structure could be the case for any struct or array passed to any function, object, or what have you. If we are to develop in a fully encapsulated realm, we can't truly trust any struct or array. In practice, we will, of course, but this just seems to be a thorn to work around. Perhaps it's a big enough thorn to attempt to eradicate in future versions?
--
Ben Curtis
WebSciences International
http://www.websciences.org/
v: 310 478 6648
f: 310 235 2067----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
