Skip to content

Instantly share code, notes, and snippets.

@schleumer
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schleumer/9009070 to your computer and use it in GitHub Desktop.
Save schleumer/9009070 to your computer and use it in GitHub Desktop.
<?php
class Users implements JsonSerializable{
private $_data = array();
public function addUser(User $user){
$this->_data[] = $user;
}
public function jsonSerialize(){
return $this->_data;
}
public function __toString(){
return json_encode($this->jsonSerialize());
}
}
class User implements JsonSerializable {
private $_name = null;
public function getName(){
return $this->_name;
}
public function setName($value){
$this->_name = $value;
}
public function jsonSerialize(){
return [
"name" => $this->_name
];
}
}
$users = new Users();
$user = new User();
$user->setName('Carinha dahora');
$users->addUser($user);
echo $users;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment