Skip to content

MIR1205

InvalidClone

The clone keyword is used on a value that PHP cannot clone: a value that is not an object (a scalar or an array), an enum case (Trying to clone an uncloneable object), or an object whose __clone() is private and called from outside its declaring class.

<?php
function duplicate(string $value): string {
return clone $value; // cannot clone a string
}

Only use clone on objects. If you need to copy a scalar or array, just assign it to a new variable (PHP copies these by value). Enum cases are singletons: use the case itself.