3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $id; public function __construct() { $this->id = 1; } public function __toString() { return $id . ""; } public function setId($id) { $this->id = $id; } } $a = new Foo; // $a is a pointer pointing to Foo object 0 $b = $a; // $b is a pointer pointing to Foo object 0, however, $b is a copy of $a $a->setId(5); unset($a); var_dump($b);

preferences:
44.72 ms | 402 KiB | 5 Q