[PHP 8.3] Added json_validate function description.#2906
Merged
Conversation
4b9d32d to
4f816f8
Compare
4f816f8 to
01cb1ee
Compare
TimWolla
reviewed
Nov 3, 2023
Comment on lines
+17
to
+26
| <para> | ||
| Check if a specified string contains a valid json. | ||
| Errors during validation can be fetched by using | ||
| <function>json_last_error</function> and/or | ||
| <function>json_last_error_msg</function>. | ||
| </para> | ||
| <para> | ||
| It's guaranteed that the json valid in <function>json_validate</function> | ||
| is also valid in <function>json_decode</function>. | ||
| </para> |
Member
There was a problem hiding this comment.
<para>
Returns whether the given &string; is syntactically valid JSON.
If <function>json_validate</function> returns &true;, <function>json_decode</function>
will successfully decode the given string when using the same
<parameter>depth</parameter> and <parameter>flags</parameters>.
</para>
<para>
If <function>json_validate</function> returns &false;, the cause
can be retrieved using <function>json_last_error</function> and
<function>json_last_error_msg</function>.
</para>
<para>
<function>json_validate</function> uses less memory than
<function>json_decode</function> if decoded JSON payload is
not used, because it does not need to build the array or
object structure containing the payload.
</para>
<caution>
<para>
Calling <function>json_validate</function> immediately before
<function>json_decode</function> will unnecessarily parse the string
twice, as <function>json_decode</function> implicitly performs
validation during decoding.
</para>
<para>
<function>json_validate</function> should therefore only be used
if the decode JSON payload is not immediately used and knowing whether
the string contains valid JSON is needed.
</para>
</caution>
Member
There was a problem hiding this comment.
Small nit to the above suggestion:
json_validate uses less memory than
json_decode if the decoded JSON payload is
not used, because it does not need to build the array or
object structure containing the payload.
Girgias
reviewed
Nov 4, 2023
Comment on lines
+59
to
+60
| Bitmask of | ||
| <constant>JSON_INVALID_UTF8_IGNORE</constant>. |
Member
There was a problem hiding this comment.
This is confusing?
Should be a bitmask of JSON_* constatns no?
Member
Author
There was a problem hiding this comment.
It seems that json_validate accepts PHP_JSON_INVALID_UTF8_IGNORE only.
if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) {
zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)");
RETURN_THROWS();
}We should change as the following?
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
Currently only
<constant>JSON_INVALID_UTF8_IGNORE</constant>
is accepted.
</para>
</listitem>
</varlistentry>
Member
There was a problem hiding this comment.
Yes I think this makes more sense. :)
Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
TimWolla
reviewed
Nov 8, 2023
Member
TimWolla
left a comment
There was a problem hiding this comment.
LGTM now, except for Girgias' remark regarding the flags parameter.
Girgias
approved these changes
Nov 14, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on RFC and json_validate source code.