I got an object. I need to turn into JSON for storage but when I try to encode it into JSON it returns an empty JSON object. When I tried to use json_last_error
.
The code I used
echo $payload["sub"];
echo json_encode($user);
echo json_last_error_msg();
The result I get
"102573480781696194937{}No error".
The User class I'm trying to encode
<?php
/**
* Created by PhpStorm.
* User: Student
* Date: 13-4-2018
* Time: 10:40
*/
namespace php;
class User
{
private $isAdmin = false;
private $registeredFood = array();
private $googleID;
private $name;
private $notes = array();
private $email;
/**
* User constructor.
* @param $googleID
*/
public function __construct($googleID)
{
$this->googleID = $googleID;
}
/**
* @return mixed
*/
public function getGoogleID()
{
return $this->googleID;
}
/**
* @return bool
*/
public function isAdmin()
{
return $this->isAdmin;
}
/**
* @param bool $isAdmin
*/
public function setIsAdmin($isAdmin)
{
$this->isAdmin = $isAdmin;
}
/**
* @return array
*/
public function getRegisteredFood()
{
return $this->registeredFood;
}
/**
* @param array $registeredFood
*/
public function setRegisteredFood($registeredFood)
{
$this->registeredFood = $registeredFood;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return array
*/
public function getNotes()
{
return $this->notes;
}
/**
* @param array $notes
*/
public function setNotes($notes)
{
$this->notes = $notes;
}
/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* @param mixed $email
*/
public function setEmail($email)
{
$this->email = $email;
}
}
?>
I hope someone can help me