3v4l.org

run code in 300+ PHP versions simultaneously
<?php class bag { protected $vals; public function __construct(array $vals) { $this->vals = $vals; } public function get($key) { return $this->vals[$key]; } } $tmp = 'foo'; $test = array( 'user' => &$tmp, ); $test['_entity'] = &$test['bar']; $bag = new bag(array_intersect_key($test, array('user' => true))); $test['user'] = 'baz'; print $bag->get('user') . "\n"; $tmp = 'foo'; $test = array( 'user' => &$tmp, ); $test['_entity'] = &$test['bar']; $temp = array_merge(array(), array_intersect_key($test, array('user' => true))); $bag = new bag($temp); $test['user'] = 'baz'; print $bag->get('user') . "\n"; $tmp = 'foo'; $test = array( 'user' => &$tmp, ); $test['_entity'] = &$test['bar']; $temp = array(); foreach (array_intersect_key($test, array('user' => true)) as $key => $value) { $temp[$key] = $value; } $bag = new bag($temp); $test['user'] = 'baz'; print $bag->get('user') . "\n";
Output for git.master, git.master_jit, rfc.property-hooks
baz baz foo

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:
41.7 ms | 401 KiB | 8 Q