Status/Resolution/Reason: To Fix//EnhancementRequired
Reporter/Name(from Bugbase): Bradley Wood / ()
Created: 11/16/2018
Components: Language
Versions: 2018
Failure Type: Others
Found In Build/Fixed In Build: /
Priority/Frequency: Normal /
Locale/System: / Platforms All
Vote Count: 1
In Lucee, there is a second, optional param to the duplicate() function which defaults to true. When I pass false, it will only duplicate the top level and all nested objects are set by reference. Basically akin to how structCopy() works except you can use it on CFC instances and you actually get a new CFC instance with all the same methods and variables as the original CFC without needing to use createObject() or new.
Here is a code snippet showing how this works on Lucee. This is very useful for frameworks like ColdBox that want to skip the performance issues of creating large numbers of identical objects by cloning a template object. A deep copy is not acceptable since the CFC may have references to many other CFCs inside of it which should not be duplicated.
https://trycf.com/gist/1d782052ee871e38efcde42a4121a2da/lucee5?theme=monokai
{code}
// Construct a CFC
oQuery = new Query();
// Decorate it with some things
oQuery.foo = 'bar';
// Create a shallow clone of the CFC into a new CFC
oQueryCopy = duplicate( object=oQuery, deepCopy=false );
// The copy has everything including foo
dump( oQueryCopy );
{code}
Attachments:
Comments: