James A Mohler
James A Mohler

Reputation: 11120

structAppend vs Duplicate

I am familiar with things like

if ( isDefined( 'URL'  ) ) structAppend( request.context, URL );
if ( isDefined( 'Form'  ) ) structAppend( request.context, Form );

Which is how FW/1 builds rc. I recently got handed some code that does this

_inputs = duplicate(url);
structAppend(_inputs, form);

What is duplicate() doing here? How is that different from structAppend()?

Upvotes: 2

Views: 247

Answers (1)

Miguel-F
Miguel-F

Reputation: 13548

I wonder if the original developer had come across issues when using the StructCopy() method and carried that over into their code for the StructAppend() method? I know that the StructCopy() method will copy nested structures by reference which can bite you. That is an example of when I use the Duplicate() method (to make a completely new copy of a structure).

I don't think that StructAppend() works that way though. Perhaps they wrote that code in an overabundance of caution. Obviously, this is just a guess.

The StructCopy() method is documented to copy by reference.

Copies a structure. Copies top-level keys, values, and arrays in the structure by value; copies nested structures by reference.

Where as the StructAppend() method makes no mention of it.

Upvotes: 3

Related Questions