Ouzo\Utilities\Json::safeDecode PHP 메소드

safeDecode() 공개 정적인 메소드

Decodes a JSON string
public static safeDecode ( string $string, boolean $asArray = false ) : mixed
$string string
$asArray boolean
리턴 mixed
    public static function safeDecode($string, $asArray = false)
    {
        if ($string === '' || $string === null) {
            // for PHP 7 compatibility
            $string = json_encode(null);
        }
        return json_decode($string, $asArray);
    }

Usage Example

예제 #1
0
파일: JsonTest.php 프로젝트: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldResetJsonError()
 {
     //given
     Json::safeDecode("error");
     Json::safeDecode("");
     //when
     $error = Json::lastError();
     //then
     $this->assertEquals(JSON_ERROR_NONE, $error);
 }