I came across an interesting scenario today using StructCopy with the URL scope.
I'm not looking for answers on how to get around it - I know/have used structAppend/duplicate etc
I wanted to copy the URL scope to a new struct so I can process/alter it without effecting the URL scope itself, so I used structCopy( url )
. I know that structcopy is a shallow copy of the struct, but as my url scope will only contain url params (as far as I know - is this correct? they are all I am interested in this case anyway) which are string key/values then I figured a shallow copy would be adequate (string being immutable and all).
However, when copying the URL scope, it resulted in strange behaviour - it appears as though structCopy(url)
just returns the url scope - not a copy of it, not an error. For example, if I perform the following (assume I have url query params, including one called "rob":
<cfset local.clonedUrl = structCopy( url ) />
<cfdump var="#local.clonedUrl#">
<cfdump var="#url#">
<cfset structDelete( local.clonedUrl, "rob" ) />
<cfdump var="#local.clonedUrl#">
<cfdump var="#url#">
In the above scenario, after the struct delete call, the clonedUrl and URL have both had the entry removed (obviously, performing the above with a normal created Struct rather than URL in the first place behaves correctly)
So, my questions are:
what? I have seen that the URL scope is actually an instance of coldfusions URLScope class, so maybe treated differently for that reason, but returning the same instance from a structCopy call is just mean. At very least if it can't do it I would expect an error, not a result that looks very similar to expected but actually exactly the behaviour I want to avoid. Also noticed that if I pass a component to structCopy it appears to have similar results.
What is the URLScope - does it extend Struct? When I dump the classname I see it is a URLScope, but just dumping the object dumps it like it would a Struct. Anyone got any advice for viewing either the sourcecode for the object or at least an API/Javadocs type spec?
I'm using CF10 (I'm not looking for answers on how to get around it - I know/have used structAppend/duplicate etc)