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

[PHP 8.3] Replace Json::isValid() implementation with new json_validate() #120

Open
aedart opened this issue Nov 4, 2022 · 2 comments
Open
Labels
enhancement New feature or request good first issue A good place to start contribution,...
Milestone

Comments

@aedart
Copy link
Owner

aedart commented Nov 4, 2022

Description

From PHP 8.3, a new json_validate can be used to determine if a string is valid json or not. This can allow us replace the current implementation of Aedart\Utils\Json::isValid().

Flags

The new json_validate also accepts depth and flags arguments. This means that the Json::isValid() method also must accept those arguments and the method signature must therefore be expanded, e.g.

    public static function isValid(mixed $value, int $depth = 512, int $options = 0): bool
    {
        if (!is_string($value)) {
            return false;
        }

        return json_validate($value, $depth, $options);
    }

Additional

json_validate() uses less memory than json_decode, which means that one could improve performance handling decoding errors, in the Json::decode() method. See article for details.

Also, perhaps we should also consider method for obtaining the last error...

@aedart aedart added enhancement New feature or request good first issue A good place to start contribution,... labels Nov 4, 2022
@aedart aedart changed the title [PHP8.3] Replace Json::isValid() implementation with new json_validate() [PHP 8.3] Replace Json::isValid() implementation with new json_validate() Nov 4, 2022
@aedart aedart added this to the v8.x milestone Jan 24, 2023
@aedart
Copy link
Owner Author

aedart commented Jan 24, 2023

This feature can, at its earliest, be added from major version 8.0 of Athenaeum, where the PHP support will be 8.2 - 8.3

@aedart aedart modified the milestones: v8.x, v9.x Mar 14, 2024
@aedart
Copy link
Owner Author

aedart commented Mar 14, 2024

For now, the current implementation of isValid() should be good enough. Once PHP 8.3 is set as the minimum required version, then the native function should be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue A good place to start contribution,...
Projects
None yet
Development

No branches or pull requests

1 participant