3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SomeHelperClass { public $_arr = []; public function addValue($value, $key = null): void { if ($key !== null) { $this->_arr[$key] = $value; } elseif (!$this->_arr) { $this->_arr[] = $value; } else { $this->_arr[max(array_keys($this->_arr)) + 1] = $value; } } } $test = new SomeHelperClass; var_export($test->_arr); echo "\n"; $test->addValue(1); var_export($test->_arr); echo "\n"; $test->addValue(2); var_export($test->_arr); echo "\n"; $test->addValue(3, 4); var_export($test->_arr); echo "\n"; $test->addValue(4, 3); var_export($test->_arr); echo "\n"; $test->addValue(5); var_export($test->_arr);
Output for git.master, git.master_jit, rfc.property-hooks
array ( ) array ( 0 => 1, ) array ( 0 => 1, 1 => 2, ) array ( 0 => 1, 1 => 2, 4 => 3, ) array ( 0 => 1, 1 => 2, 4 => 3, 3 => 4, ) array ( 0 => 1, 1 => 2, 4 => 3, 3 => 4, 5 => 5, )

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:
26.6 ms | 405 KiB | 5 Q