3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Reference { private static $DATA = []; private $index = 0; public function __construct($value) { // cannot create a reference of a reference if ($value instanceof self) { $this->index = $value->index; } else { $this->index = count(self::$DATA); self::$DATA[$this->index] = $value; } } public function get() { return self::$DATA[$this->index]; } public function set($value) { self::$DATA[$this->index] = $value; } } $orig = [1]; // $ref =& $orig[0]; $orig[0] = new Reference($orig[0]); $ref = clone $orig[0]; $copy = $orig; $copy[0] = clone $orig[0]; // creating a copy of what was in $orig[0] // $orig[0] = 10; $orig[0]->set(10); // var_dump($copy[0]); var_dump($copy[0]->get());
Output for git.master, git.master_jit, rfc.property-hooks
int(10)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
27.7 ms | 405 KiB | 5 Q