MIR1206
PossiblyInvalidClone
The clone keyword is used on a value with a union type where at least one member is not an
object. At runtime, if the non-object branch is taken, a fatal error will occur.
Example
Section titled “Example”<?phpfunction duplicate(object|null $value): ?object { return clone $value; // $value could be null}How to fix
Section titled “How to fix”Narrow the type before cloning, or handle the non-object case explicitly:
<?phpfunction duplicate(object|null $value): ?object { return $value !== null ? clone $value : null;}