Hi,

On Fri, Jul 4, 2025 at 11:49 PM Valentin Udaltsov <
udaltsov.valen...@gmail.com> wrote:

> On Sta, 5 July 2025 at 00:04, Jakub Zelenka <bu...@php.net> wrote:
>
>> Hello,
>>
>> I would like introduce and open discussion for RFC proposing the addition
>> of JSON Schema validation support to JSON extension:
>>
>> https://wiki.php.net/rfc/json_schema_validation
>>
>> If this is successful, it should be just the first for further
>> improvements (see the future scope).
>>
>> Kind regards,
>>
>> Jakub
>>
>
> Hi, Jakub!
>
> I like the idea. I have a couple of initial thoughts:
>
> 1. Wouldn't it make sense to place all the new classes under the `Json`
> namespace, similar to how it’s done in `ext-random`?
>

This would be widely inconsistent with the current interface / exception
class in the extension. The ext-random was a new extension so it's a
completely different case. I think it makes much more sense to keep the
extension consistent than introducing new interface.


> 2. If there’s no way to interact with the `JsonSchema` class, what purpose
> does it serve? Wouldn’t it be simpler to just extend `json_decode()` with
> an optional `?string $schema = null` parameter?
>

There are couple of reasons for this:

- It allows re-using the same parsed schema without a need to parse it
multiple times for each decoding / validation - the class internally holds
parsed representation of the schema.
- We might want to introduce additional flags that will impact the parsing
(e.g. default version)
- It might allow a way to better cache schema between requests so it could
further improve performance in the future
- It will allow the possibility to get schema from other sources than
string - e.g. from PHP array or even automatic creation from the class
(that's why the JsonSchema is created using static method and not using
constructor). This might be especially useful for object mapping.

Kind regards,

Jakub

Reply via email to