json - PHP Fatal Error from json_decode inside try-catch -
the following code throws me exception:
$return = json_decode($result);   fatal error: cannot access property started '\0' in file.php on line 36
i've read php documentation , questions here, i've tried code:
try{    $return = json_decode($result);   }   catch(exception $e)   {     $json_error_code = json_last_error();    echo $json_error_code . ",";    $err.= 'json parse error';    switch ($json_error_code) {     case json_error_none:      $err = "none";      break;     case json_error_depth:      $err.= ' - maximum stack depth exceeded';      break;     case json_error_state_mismatch:      $err.= ' - underflow or modes mismatch';      break;     case json_error_ctrl_char:      $err.= ' - unexpected control character found';      break;     case json_error_syntax:      $err.= ' - syntax error, malformed json';      break;     case json_error_utf8:      $err.= ' - malformed utf-8 characters, possibly incorrectly encoded';      break;     default:      $err.= ' - unknown error';      break;    }    echo $err;   }   it throws same fatal error - in try-catch block!
can me solve this?
thanks!
firstly remove try catch block json_decode not throw exceptions. secondly create $err change line
$err.= 'json parse error';   to
$err= 'json parse error';   you try concatenate strings variable not exists.
remove break default: it's useless.
after it should work.
notice: if want errors behave exceptions need use own error handler
if json_encode gives fatal error try reinstalling json extension , see https://bugs.php.net/bug.php?id=68546
Comments
Post a Comment