[ create a new paste ] login | about

Link: http://codepad.org/14UxhtKN    [ raw code | fork ]

phpfour - PHP, pasted on Mar 31:
<?php

trait JSONized {

    public function toJson()
    {
        $properties = get_object_vars($this);
        return json_encode($properties);
    }

}

class User
{
    use JSONized;

    public $username;
    public $password;
    public $email;

    public function __construct($username, $password, $email)
    {
        $this->username = $username;
        $this->password = md5($password);
        $this->email = $email;
    }
}

$emran = new User('phpfour', 'emran123', 'phpfour@gmail.com');
echo $emran->toJson();


Create a new paste based on this one


Comments: