Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PHP native json_validate in isJson function if available #48367

Merged
merged 1 commit into from Sep 12, 2023

Conversation

jnoordsij
Copy link
Contributor

PHP 8.3 introduces a json_validate function, which allows validating if a string contains valid json with less resource and memory consumption than using the json_encode function.

This PR uses the new function when it's available and thus is backwards compatible with older PHP versions, while taking advantage of the new function on PHP >= 8.3.

Note that Symfony has a polyfill for this, which is probably what will be used in practice by most existing Laravel installations using PHP < 8.3 (as the polyfills are loaded with recent versions of symfony/http-foundation), which would allow removing the json_decode call sometime in the future.

See also the RFC.

@taylorotwell taylorotwell merged commit a02a39b into laravel:10.x Sep 12, 2023
20 checks passed
@driesvints
Copy link
Member

@jnoordsij nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants