codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?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();
Private
[
?
]
Run code
Submit