Given your test case Adam, I initially thought the problem was down to the function return handling.

But given Sean's example, I see it's actually the assignment where things are going wrong.

I can fix that particular issue by duplicating the value when the RHS of the assignment operation is an array but that seems overkill and likely to introduce a new issue if there are situations where you wouldn't expect that to happen. Just trying to think if there are any.

Thoughts welcomed.

Andy

Adam Cameron wrote:
G'day
This is an inconsistency with CF that Railo shares with BD.  I'm not
sure why my tests show this up on Railo but not BD though... I need to
look at that... hmmm...

Ah.  I've worked out the difference in my repro case and my live code.

This new repro case demonstrates an idiosyncracy in OpenBD (and
slightly different behaviour in BD.NET) in the way it deals with the
array value/reference thing.

<!--- Numbers.cfc --->
<cfcomponent>

        <cfset variables.aNumbers = listToArray("tahi,rua,toru")>

        <cffunction name="getNumbers" returntype="array">
                <cfreturn variables.aNumbers>
        </cffunction>

        <cffunction name="getNumbers2" returntype="array">
                <cfset var a = variables.aNumbers>
                <cfreturn a>
        </cffunction>

        <cffunction name="getNumbers3" returntype="array">
                <cfset var a = arrayNew(1)>
                <cfset a = variables.aNumbers>
                <cfreturn a>
        </cffunction>

</cfcomponent>

<!--- callNumbers.cfm --->
<cfset o = createObject("component", "Numbers")>

<cfset aNumbers1 = o.getNumbers()>
<cfset arrayAppend(aNumbers1, "wha")>
<cfdump var="#aNumbers1#">

<cfset aNumbers2 = o.getNumbers()>
<cfset arrayAppend(aNumbers2, "wha")>
<cfdump var="#aNumbers2#">
<hr />


<cfset o2 = createObject("component", "Numbers")>

<cfset aNumbers3 = o2.getNumbers2()>
<cfset arrayAppend(aNumbers3, "wha")>
<cfdump var="#aNumbers3#">

<cfset aNumbers4 = o2.getNumbers2()>
<cfset arrayAppend(aNumbers4, "wha")>
<cfdump var="#aNumbers4#">
<hr />


<cfset o3 = createObject("component", "Numbers")>

<cfset aNumbers5 = o3.getNumbers3()>
<cfset arrayAppend(aNumbers5, "wha")>
<cfdump var="#aNumbers5#">

<cfset aNumbers6 = o3.getNumbers3()>
<cfset arrayAppend(aNumbers6, "wha")>
<cfdump var="#aNumbers6#">

On CF, all of getNumbers(), getNumbers2() and getNumbers3() copy the
value, so all results are "tahi, rua, toru, wha".  Uniform - if less
than ideal - behaviour.  Good.

On Railo, all of the methods copy the reference, so "wha" gets doubled-
up.  Uniform behaviour.

On OpenBD, getNumbers() and getNumbers2() copy the reference.
getNumbers3() copies the VALUE.

On BD.NET, getNumbers() copies the reference, but getNumbers2() and
getNumbers3() copy the value.

I would have thought the two BD flavours should have the same
behaviour across all three methods?  I can see why they don't: there's
a different process going on when one returns something, to when a
variable is initialised, to when a variable is assigned.  But - really
- shouldn't they all be implemented to do it the same way?

Or am I missing something? (Entirely likely...)

--
Adam


--
Open BlueDragon Public Mailing List
http://www.openbluedragon.org/   http://twitter.com/OpenBlueDragon
official manual: http://www.openbluedragon.org/manual/
Ready2Run CFML http://www.openbluedragon.org/openbdjam/

mailing list - http://groups.google.com/group/openbd?hl=en

Reply via email to