Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BaseModel // All models extend this class
- {
- // Returns an object with each property set to its own name as a string
- /* @return static */
- public static function getNameObject()
- {
- $obj = (object) get_class_vars(get_called_class()); // Note: Avoids calling constructor
- foreach (get_object_vars($object) as $key => $value) {
- $object->{$key} = $key;
- }
- return $obj;
- }
- }
- class User extends BaseModel
- {
- public $id;
- public $name;
- }
- <?php $u = User::getNameObject(); ?>
- var user = getUserFromServer();
- var userId = user.<?=$u->id?>;
- var userName = user.<?=$u->name?>;
Add Comment
Please, Sign In to add comment