Created
April 21, 2012 06:24
-
-
Save hmert/2434743 to your computer and use it in GitHub Desktop.
This file contains 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
trait JSONized { | |
public function toJson() | |
{ | |
$properties = get_object_vars($this); | |
return json_encode($properties); | |
} | |
} |
This file contains 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
include_once 'JSONized.php'; | |
include_once 'User.php'; | |
$hede = new User('h', 'm', 'hede@hede.com'); | |
echo $hede->toJson(); |
This file contains 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
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