Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Last active June 5, 2019 13:23
Show Gist options
  • Save kobus1998/3c86950651efc7e1f7ca4a5bbe0da4c5 to your computer and use it in GitHub Desktop.
Save kobus1998/3c86950651efc7e1f7ca4a5bbe0da4c5 to your computer and use it in GitHub Desktop.
php dictonary
<?php
trait Dictionary
{
public function __call($method, $args = [])
{
if (empty($args)) {
return $this->{$method};
}
$this->{$method} = reset($args);
return $this;
}
}
class UserEntity
{
use Dictionary;
public $id;
public $name;
public $password;
public $isAdmin;
}
$user = (new UserEntity())
->id(1)
->name('admin')
->password('passy')
->isAdmin(true);
echo $user->name(); // admin
print_r($user);
/*
UserEntity Object
(
[id] => 1
[name] => admin
[password] => passy
)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment