rfc:always_enable_json

This is an old revision of the document!


PHP RFC: Always Enable JSON

Introduction

Currently, it's possible to disable the json extension with ./configure --disable-json. However, JSON is extremely useful to have - it's widely used in many use cases (web sites, logging output, and as a data format that can be used to share data with many applications and programming languages), so it would be useful for PHP maintainers and users to guarantee that it's always enabled.

Examples of where this would be useful:

  • Allowing internal classes to implement `JsonSerializable`, which currently requires a hard dependency on the JSON extension.
    (e.g. DateTime already has custom JSON serialization behavior, but is unable to implement JsonSerializable normally)
  • Allowing PHP users to publish single-file scripts that use json_encode and json_decode and don't require polyfills or less readable var_export output.
    (polyfills are less efficient and may have issues with recursive data structures)
  • Letting php-src's own modules, tools and .phpt test cases start using JSON if it's a good choice for representing a value. (same for PECLs)

The reasons for allowing JSON to be disabled appear to be historical, and no longer apply. https://wiki.php.net/rfc/jsond mentions that:

The current Json Parser (for PHP 5) in the json extension does not have a free license
which is a problem for many Linux distros.
This has been referenced at Bug #63520.
That results in not packaging json extension in the many Linux distributions.

Starting in php 7.0 with the switch to jsond, it looks like licensing is no longer an issue.

Proposal

Make it impossible to disable the JSON extension through configuration or build options. Require that JSON be built statically instead of as a shared library.

Backward Incompatible Changes

The HAVE_JSON C macro constant was removed from the generated main/php_config.h, because it's always true (the removal of macros that are no longer useful are typically reserved for major versions such as 8.0).

  • Libraries should check #if HAVE_JSON

Because JSON would always be built statically to guarantee it can be used, package maintainers for OSes such as Fedora would need to create stub packages for the php-json package, or to remove the package in php 8.

Some other OSes already use JSON statically by default (e.g. the zips published on windows.php.net, or the default when building php from source)

Proposed PHP Version(s)

8.0

Future Scope

- Start using JSON in more places within PHP's own functions. For example, adding additional conversion specifiers for printf() such as %j or %v to PHP to call JSON with the default options.

- Add alternative options to use JSON to dump debug output in an easily machine-readable form. (e.g. opcache.opt_debug_level debug output is plaintext right now)

Proposed Voting Choices

Make the JSON extension impossible to disable (Yes/No vote, requiring 2/3 majority)

References

rfc/always_enable_json.1588203221.txt.gz · Last modified: 2020/04/29 23:33 by tandre