3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo_DTO { public function __construct( array $data ) { array_map( function ( $r ) use ( $data ) { if ( ! array_key_exists( $r, $data ) ) { throw new \UnexpectedValueException( 'Required key "%s" does not exist.', $r ); } }, [ 'id', 'name', 'username' ] ); $this->id = $data['id']; $this->name = $data['name']; $this->username = $data['username']; } public function get_id() { return (string) $this->id; } public function get_name() { return (string) $this->name; } public function get_username() { return (string) $this->username; } } $foo = new Foo_DTO(['id' => 123, 'name' => 'Foo', 'username' => 'foo']); echo $foo->get_id() . PHP_EOL; echo $foo->get_name() . PHP_EOL; echo $foo->get_username() . PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property Foo_DTO::$id is deprecated in /in/cpWcq on line 11 Deprecated: Creation of dynamic property Foo_DTO::$name is deprecated in /in/cpWcq on line 12 Deprecated: Creation of dynamic property Foo_DTO::$username is deprecated in /in/cpWcq on line 13 123 Foo 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:
146.17 ms | 406 KiB | 5 Q