On Tuesday, Apr 1, 2003, at 12:19 US/Pacific, Howard Fore wrote:
Student.cfc:
<cfcomponent displayname="Student">

    <cfproperty name="FirstName" type="string">
    <cfproperty name="LastName" type="string">
    <cfproperty name="StudentNumber" type="string">
    <cfproperty name="StudentSequence" type="numeric" default="0">
    <cfproperty name="UserName" type="string">
    <cfproperty name="Password" type="string">

First off, the cfproperty tags are having no effect on your code - you might as well remove them.


<cffunction name="new" output="false">
<cfargument name="UserName" type="string" required="false">
<cfargument name="Password" type="string" required="false">
<cfargument name="StudentNumber" type="string" required="false">
<cfargument name="StudentSequence" type="numeric" required="false" default="0">

It seems that inside the function, the arguments struct automatically contains all of the keys of both the arguments you pass in *and* the cfargument tags you define.


Here's a simpler example that shows the behavior:

        <cfcomponent dissplayname="howard.cfc">
                <cffunction name="foo" returntype="struct">
                        <cfargument name="one" required="false">
                        <cfargument name="two" required="false">
                        <cfif isDefined("arguments.one")>one is defined</cfif>
                        <cfif isDefined("arguments.two")>two is defined</cfif>
                        <cfif structKeyExists(arguments,"one")>one exists</cfif>
                        <cfif structKeyExists(arguments,"two")>two exists</cfif>
                        <cfreturn arguments>
                </cffunction>
        </cfcomponent>

howard.cfm:

        <cfoutput>
        <cfinvoke component="howard" method="foo" returnvariable="bar"
                two="2">
        </cfinvoke>
        <cfdump label="bar" var="#bar#">
        </cfoutput>

What you will see is:
- isDefined() returns false for one, true for two (as you should expect)
- structKeyExists() also returns false for one, true for two (again, as you should expect)


However the cfdump output will show that the returned arguments structure contains a key called "ONE" with [undefined struct element].

If you check arraylen() or structCount() of arguments, it'll return 2 - which the cfdump confirms.

So it seems that specifying cfargument with required="false" creates that entry in the arguments struct but does not populate it. Furthermore, it seems that attempting to check the length of the arguments list is not reliable in that it will always return at least as many elements as you have cfargument tags.

Since your conditions are exclusive you can easily solve your immediate problem by using cfelseif and cascade your tests (instead of having a separate cfif for each one).

An interesting problem!

Sean A Corfield -- http://www.corfield.org/blog/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email.


CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

Reply via email to