I have a User object and I want to encode it to a JSON format, but json_encode()
returns an empty value "{}"
. What I am doing wrong?
Here's my code:
<?php
header('Content-Type: application/json');
require_once 'DataBase.php';
include_once '../Model/User.php';
$user = DataBase::getUser('username', $_GET['q']); //getting User object
$json = json_encode($user); //returns "{}"
echo $json;