Skip to content

MIR1205

InvalidClone

The clone keyword is used on a value that is not an object. PHP’s clone operator is only valid for objects; using it on scalars or arrays produces a fatal error.

<?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).