3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('America/Los_Angeles'); class Test { public $previous, $next = NULL; public function __clone() { $this->previous != NULL ? $this->previous = clone $this->previous : $this->previous = NULL; $this->next != NULL ? $this->next = clone $this->next : $this->next = NULL; } public function __toString() { return '[' . ($this->previous != NULL ? '<' : '-') . ' ' . ($this->next != NULL ? '>' : '-') . ']'; } } // Create some test objects $a = new Test(); $b = new Test(); // Link them together $a->next =& $b; $b->previous =& $a; // Clone and print echo "a before cloning:\na: " . $a . "\n"; $b = clone $a; echo "These two should not look the same:\na: " . $a . "\nb: " . $clone . "\n";
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.23, 7.4.0 - 7.4.12, 8.0.0alpha1 - rc2
a before cloning: a: [- >]
Process exited with code 139.