Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-79895

PHP 8.3: Added json_validate function

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor Minor
    • None
    • 4.4
    • General

      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

      1. 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
      2. 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
      3. If we do make change, it will be to master only.

            dobedobedoh Andrew Lyons
            dobedobedoh Andrew Lyons
            Raquel Ortega Raquel Ortega
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 30 minutes
                1h 30m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.