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"; // Expected result: // ---------------- // a before cloning: // a: [- >] // These two should not look the same: // a: [- >] // b: [- -] // // // Actual result: // -------------- // a before cloning: // a: [- >] // Segmentation fault

preferences:
38 ms | 402 KiB | 5 Q