-
Improvement
-
Resolution: Done
-
Minor
-
None
-
4.4
-
MOODLE_404_STABLE
PHP 8.3 adds a new function named json_validate that returns true or false whether the given string is a valid JSON string.
Prior to PHP 8.3, the only way to determine if a given string is a valid JSON string was to attempt to decode it, and see if any errors were emitted. The new json_validate function uses the same underlying JSON parser PHP uses, but consumes less memory and processing as json_decode only analyzes the string without constructing any decoded value.
Applications that have strong measures to prevent invalid JSON strings from being processed may not find the new json_validate function useful, because a json_validate call immediately followed by a json_decode can slightly increase the execution time as the JSON string is analyzed twice, and there is a higher chance of the input JSON string being valid JSON in the place.
Applications that accept user-provided JSON, or connect remote JSON APIs may find the best use of the new json_validate, because there is a significant chance of encountering invalid JSON strings.
Required
- No change is required but we may want to look at using the new json_validate in places where we currently perform poor-man's validation
- If we do opt to use the new validation method, we must perform a PHP version check and raise a new MDL to remove the old method when we cease support for PHP 8.2
- If we do make change, it will be to master only.
- duplicates
-
MDL-76427 PHP 8.3: Added json_validate function
-
- Closed
-
- has a non-specific relationship to
-
MDL-80144 Validation only: Confirm a collection of PHP 8.3 issues are no-op
-
- Closed
-
- will be (partly) resolved by
-
MDL-80350 PHP 8.3 - Use the new json_validate function where a poor-man's validation is performed
-
- Open
-