Null value when accessing object property created by decoding JSON string

vietha20

New Member
In my PHP script I need to decode a Json string and then transfer the decoded value to a class. Something like:index.php\[code\]$params = json_decode('input');$obj = new User();$obj->setParams($params);$obj->Register();\[/code\]class.php\[code\]class User{private $mParams;public function setParams($params) $mParams = $params;}public function Register(){ $username = $mParams->{'username'}; $password = $mParams->{'password'};}....}\[/code\]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.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.Thanks,
 
Top