per-coding-style icon indicating copy to clipboard operation
per-coding-style copied to clipboard

PHP 8.5: Always require parentheses around `clone()`

Open TimWolla opened this issue 2 months ago • 0 comments

Following #109.

With PHP 8.5 clone() is now a proper function that still supports a parentheses-less syntax for compatibility purposes, but requires parens for the new clone-with functionality. For consistency it should always be used with parentheses.

Correct:

$cloned = clone($obj);
$cloned = clone($obj, $with);
$cloned = clone($obj, ['prop' => $prop]);
$cloned = clone($obj, [
    'prop' => $prop,
]);
$cloned = \clone($obj);

function_call(clone($obj), $value);

Incorrect:

$cloned = clone $obj;
function_call(clone $obj, $value);

TimWolla avatar Oct 05 '25 13:10 TimWolla