3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Struct { function __construct() { foreach (func_get_args() as $name) { $this->$name = null; } } function __invoke(... $values) { $obj = clone $this; foreach ($this as $index => $name) { var_dump([$index, $name]); if ( isset($values[$index]) ) { $obj->$name = $values[$index]; } } return $obj; } } $Coord = new Struct('x', 'y', 'z'); $Coord->z = 0; $c1 = $Coord(12, 45, -34); print_r($c1); $c2 = $Coord(100, -100); print_r($c2); $Person = new Struct('firstname', 'lastname'); $p1 = $Person('William', 'Wallace'); print_r($p1); $p2 = $Person('Peter', 'Griffin'); print_r($p2);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property Struct::$x is deprecated in /in/2f59J on line 7 Deprecated: Creation of dynamic property Struct::$y is deprecated in /in/2f59J on line 7 Deprecated: Creation of dynamic property Struct::$z is deprecated in /in/2f59J on line 7 array(2) { [0]=> string(1) "x" [1]=> NULL } array(2) { [0]=> string(1) "y" [1]=> NULL } array(2) { [0]=> string(1) "z" [1]=> int(0) } Struct Object ( [x] => [y] => [z] => 0 ) array(2) { [0]=> string(1) "x" [1]=> NULL } array(2) { [0]=> string(1) "y" [1]=> NULL } array(2) { [0]=> string(1) "z" [1]=> int(0) } Struct Object ( [x] => [y] => [z] => 0 ) Deprecated: Creation of dynamic property Struct::$firstname is deprecated in /in/2f59J on line 7 Deprecated: Creation of dynamic property Struct::$lastname is deprecated in /in/2f59J on line 7 array(2) { [0]=> string(9) "firstname" [1]=> NULL } array(2) { [0]=> string(8) "lastname" [1]=> NULL } Struct Object ( [firstname] => [lastname] => ) array(2) { [0]=> string(9) "firstname" [1]=> NULL } array(2) { [0]=> string(8) "lastname" [1]=> NULL } Struct Object ( [firstname] => [lastname] => )

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.09 ms | 403 KiB | 8 Q