Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用\Phalcon\HTTP\ResponseInterface\setJsonContent()时出错_Php_Json - Fatal编程技术网

Php 使用\Phalcon\HTTP\ResponseInterface\setJsonContent()时出错

Php 使用\Phalcon\HTTP\ResponseInterface\setJsonContent()时出错,php,json,Php,Json,我有一个RESTAPI,我使用setJsonContent()输出(显然)一些json内容 在版本1.2.2之前,它工作正常,但由于我使用的是版本1.2.4(现在是1.2.6),它最终开始显示以下警告: PHP警告:json_encode()[function.json encode]:参数中的UTF-8序列无效 它只是偶尔发生,我不知道如何跟踪这个错误。使用本机json_encode()不会对相同的数据显示相同的错误 我无法追踪确切的数据,因为我有一个庞大的数据库。有没有办法获得导致这种情况的

我有一个RESTAPI,我使用setJsonContent()输出(显然)一些json内容

在版本1.2.2之前,它工作正常,但由于我使用的是版本1.2.4(现在是1.2.6),它最终开始显示以下警告: PHP警告:json_encode()[function.json encode]:参数中的UTF-8序列无效

它只是偶尔发生,我不知道如何跟踪这个错误。使用本机json_encode()不会对相同的数据显示相同的错误


我无法追踪确切的数据,因为我有一个庞大的数据库。有没有办法获得导致这种情况的确切字节?

Phalcon在内部使用本机的
json\u encode()
(警告消息确认了这一点),因此无论您是否使用Phalcon,您都应该面临同样的问题

我建议将此警告转换为异常,然后在
catch
块中记录数据,然后检查它们

它看起来像这样:

function handleError($errno, $errstr, $errfile, $errline, array $errcontext)
{
    if (0 === error_reporting()) {
        return false;
    }

    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}

// Put this right before the code that produces the warning
set_error_handler('handleError');
try {
    // The code that might trigger the warning
}
catch (ErrorException $e) {
    // Log the data
}

restore_error_handler()