Skip to content

CodeIgniter\Format\JSONFormatter needs a look. #544

Closed
@ivantcholakov

Description

@ivantcholakov

Current code: https://github.com/bcit-ci/CodeIgniter4/blob/26cee0f2d3f6327825ebbe9f84f50e10ef4bf339/system/Format/JSONFormatter.php

1
The property $errors (the array) is not needed, because there is the PHP function json_last_error_msg() that does the job. http://php.net/manual/en/function.json-last-error-msg.php

2
$result = json_encode($data, 512, $options);
Argument placement is wrong, it should be:
$result = json_encode($data, $options, 512); http://php.net/manual/en/function.json-encode.php

3
"If result is NULL, then an error happened." - this is not true. FALSE is returned on failure. But since FALSE could be a valid result, it would be better json_last_error() !== JSON_ERROR_NONE to be the condition about failure detection.

4
return utf8_encode($result);
Why utf8_encode() usage is needed here? I think, it should be removed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions