 # [Usage](../../../usage.md) > Universal Deep Cloner

Use `UniversalDeepClone` when you need a true in-memory copy of a component or object graph — e.g. duplicating a `Form` schema branch — so mutating the clone never affects the original. For database rows prefer [Model Syncer](model_syncer.md) (reconcile) or [Records Cloner](records_cloner.md) (duplicate scope); this trait is for objects, arrays, queries and closures held in PHP memory.

`UniversalDeepCloner` is backend trait, originally created to clone objects but can clone everything:

- Objects
- Queries
- Functions
- Variables
- Array

Is called "Deep Cloner" because it can also clone everything recursively inside the object properties/arrays.

---

## How to use

Simply replace in your class the `__clone()` function with the trait:

```php
<?php

class Object {

    public function __clone() {
        // standard clone method
    }
    
}
```

to:

```php
<?php

class Object {
    
    use KFramework\Traits\UniversalDeepClone;
        
    // clone function removed, now implemented into UniversalDeepClone class

}
```

You can now clone the object as always:

```php
$obj = new Object;

$objectInstance = clone $obj;
```

## When to pick which

| Need | Use |
| ---- | --- |
| Reconcile DB rows (create + update + delete in scope) | [Model Syncer](model_syncer.md) |
| Duplicate DB rows from one scope value to another | [Records Cloner](records_cloner.md) |
| Deep-clone an in-memory object graph | `UniversalDeepClone` trait (this page) |

Controller-style example cloning a component branch:

```php
use KFramework\Components\Forms\Input;

$original = Input::make('name')->setLabel('Name');
$copy = clone $original; // deep-cloned, fresh UUID via the trait
$copy->setName('surname')->setLabel('Surname');
```

## See also

- [Usage](../../../usage.md)
- [Model Syncer](model_syncer.md) / [Records Cloner](records_cloner.md) — database-row alternatives
- [Form component](../../components/forms/form.md) — components using this trait get a fresh UUID on `clone`
