<?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;
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`