Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Clone Clone Clone

<?php

class a {}
$a = new a;
// object(a)#1 (0) {}

var_dump($b = clone clone clone $a);
// object(a)#2 (0) {}

var_dump(new (new $a));
// object(a)#3 (0) {}

It is possible to chain clone operators : PHP optimize this and skips any intermediate clone. The resulting final object is number 2, so the inner clones were duly ignored.

On the other hand, it is possible to create a new object from an existing object, but it is not possible to chain the new calls without using parenthesis.

See Also

PHP Features

Last updated: 09 November 2026