Creating a copy of an object with fully replicated properties is not always the wanted behavior.
<?php
class Father
{
public $counter = 0;
public function speak()
{
$this->counter++;
echo $this->counter . PHP_EOL;
}
public function increase()
{
$this->counter++;
}
}
$father = new Father();
$father->speak();
$child = clone $father;
echo $child->speak();
$child->increase();
echo PHP_EOL;
echo $father->counter . PHP_EOL;
//variables in child are reference to the fathers' variables
echo $child->counter . PHP_EOL;
?>