json_encode gives unexpected result
<p>I want to encode an object using JSON to answer an AJAX request. First, I convert the object to an array (the result of this looks okey), then I use <code>json_encode</code> to encode the array to the JSON format, but I get an unexpected result. The obtained JSON string has the class name before the property names and the null character '\0000' appears in many places. All of my files are encoded using UTF-8. If I use <code>get_object_vars</code>, the I get the result <code>array = []</code>.</p>

<p>How I can resolve this issue?</p>

<p>I got result: <code>{"\u0000DB\u0000connection":null,"\u0000DB\u0000serverName":"localhost","\u0000DB\u0000userName":"root","\u0000DB\u0000password":null,"\u0000DB\u0000dbName":"thahtin"}</code></p>

<p>Here is the code I used:</p>

<pre><code>class DB
{
    private $connection;
    private $serverName;
    private $userName;
    private $password;
    private $dbName;

    public function __construct()
    {
        $config = new Configuration();
        $this-&gt;serverName = 'localhost'; //$config-&gt;getConfig("server");
        $this-&gt;userName = 'root'; //$config-&gt;getConfig("userName");
        $this-&gt;password = null; //$config-&gt;getConfig("password");
        $this-&gt;dbName = 'thahtin'; //$config-&gt;getConfig("database");
    }       

    public function open()
    {
        if(!$this-&gt;connection)
            mysql_close($this-&gt;connection);
        $this-&gt;connection = mysql_connect($this-&gt;serverName, $this-&gt;userName, $this-&gt;password);
        if(!$this-&gt;connection)
        {
            die('Could not connect. Error: ' . mysql_error());
        }
        mysql_select_db($dbName);
    }
}

$db = new DB();
echo json_encode((array)$db);
</code></pre>
