Last active
June 5, 2019 13:23
-
-
Save kobus1998/3c86950651efc7e1f7ca4a5bbe0da4c5 to your computer and use it in GitHub Desktop.
php dictonary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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