Skip to content

Instantly share code, notes, and snippets.

@hmert
Created April 21, 2012 06:24
Show Gist options
  • Save hmert/2434743 to your computer and use it in GitHub Desktop.
Save hmert/2434743 to your computer and use it in GitHub Desktop.
trait JSONized {
public function toJson()
{
$properties = get_object_vars($this);
return json_encode($properties);
}
}
include_once 'JSONized.php';
include_once 'User.php';
$hede = new User('h', 'm', 'hede@hede.com');
echo $hede->toJson();
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment