Null value when accessing object property created by decoding JSON string
<p>In my PHP script I need to decode a Json string and then transfer the decoded value to a class. Something like:</p>

<p>index.php</p>

<pre><code>$params = json_decode('input');
$obj = new User();
$obj-&gt;setParams($params);
$obj-&gt;Register();
</code></pre>

<p>class.php</p>

<pre><code>class User{
private $mParams;

public function setParams($params)
    $mParams = $params;
}

public function Register(){
    $username = $mParams-&gt;{'username'};
    $password = $mParams-&gt;{'password'};
}
....
}
</code></pre>

<p>The problem is, in Register(), when I print the $username and $password, I just got NULL. But I'm sure the $params decoded from Json is not NULL because, if I print it in setParams, I can get username and password. And, if I directly transfer the $params to Register() everything is fine.</p>

<p>So I feel strange that why I can not set the $params to the class's member and then call the class's member function to access it.</p>

<p>Thanks,</p>
