Always available JSON extension View as Markdown

Implemented (PHP 8.0)
Authors
Tyson Andre tandre@php.net
Date
2020-04-29
Version
0.3
Target
PHP 8.0
Implementation
https://github.com/php/php-src/pull/5495
Source
wiki.php.net/rfc/always_enable_json

Vote

Make the JSON extension impossible to disable closed
Yes
56
No
0
56 voters
alcaeus Yes 2020-05-14 13:17
asgrim Yes 2020-05-13 14:02
ashnazg Yes 2020-05-21 17:08
beberlei Yes 2020-05-13 14:27
bmajdak Yes 2020-05-13 15:18
bwoebi Yes 2020-05-13 13:56
carusogabriel Yes 2020-05-14 10:19
chregu Yes 2020-05-13 13:56
cmb Yes 2020-05-13 14:51
colinodell Yes 2020-05-13 14:15
dams Yes 2020-05-13 14:59
derick Yes 2020-05-13 15:47
dmitry Yes 2020-05-18 08:39
dragoonis Yes 2020-05-13 19:10
duncan3dc Yes 2020-05-17 12:03
duodraco Yes 2020-05-22 21:12
ekin Yes 2020-05-13 20:54
galvao Yes 2020-05-14 01:17
girgias Yes 2020-05-13 13:46
guilhermeblanco Yes 2020-05-26 14:05
jasny Yes 2020-05-15 13:46
jbnahan Yes 2020-05-15 11:50
jhdxr Yes 2020-05-13 23:15
kalle Yes 2020-05-13 15:33
kguest Yes 2020-05-22 07:25
kocsismate Yes 2020-05-13 13:34
lcobucci Yes 2020-05-13 20:08
levim Yes 2020-05-18 02:09
lstrojny Yes 2020-05-15 11:48
marandall Yes 2020-05-13 16:28
marcio Yes 2020-05-15 22:06
mariano Yes 2020-05-13 14:59
mfonda Yes 2020-05-14 15:58
nicolasgrekas Yes 2020-05-13 13:59
nikic Yes 2020-05-14 13:16
ocramius Yes 2020-05-13 13:57
patrickallaert Yes 2020-05-14 08:53
petk Yes 2020-05-13 15:02
pmjones Yes 2020-05-13 16:12
pollita Yes 2020-05-13 14:44
ramsey Yes 2020-05-14 19:02
reywob Yes 2020-05-14 08:34
rtheunissen Yes 2020-05-15 19:54
ruudboon Yes 2020-05-16 16:52
salathe Yes 2020-05-13 15:54
santiagolizardo Yes 2020-05-15 13:21
sebastian Yes 2020-05-13 15:26
sergey Yes 2020-05-14 19:51
svpernova09 Yes 2020-05-15 12:39
tandre Yes 2020-05-13 19:59
till Yes 2020-05-14 10:33
trowski Yes 2020-05-21 17:16
villfa Yes 2020-05-14 08:17
wyrihaximus Yes 2020-05-14 10:56
yunosh Yes 2020-05-14 07:15
zimt Yes 2020-05-15 08:45

Discussions on the mailing list

Moving json extension to core?
by tyson andre · 6 messages
[RFC] Always available JSON extension
by tyson andre · 5 messages
[VOTE] Always available json extension
by tyson andre · 2 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:51 UTC

Introduction

Currently, it's possible to disable the json extension with ./configure --disable-json. However, JSON is extremely useful to have because it's widely used for 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 json is 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 because that interface doesn't always exist.)

  • 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://externals.io/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.

Extensions have been made always-on by default. For example, e.g. https://wiki.php.net/rfc/permanent_hash_ext did this for the hash extension.

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

Build configurations that contain --enable-json or --disable-json will have to be updated, as the argument will cease to exist.

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 (or mark it as provided by the core php package).

Some other installations 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

RFC Impact

To SAPIs and Existing Extensions

PECL extensions can now always rely on the json extension to be available and use its API and PHP interfaces such as JsonSerializable.

Minimal builds of PHP will slightly grow in size.

Unaffected PHP Functionality

Any already existing userland code will continue to work as before. Userland code may remove calls to extension_loaded('json') as they will now always return true.

The json extension does not have any external dependencies, so this will not add any more dependencies for a minimal build of PHP.

Future Scope

  • Make internal classes that already have custom JSON serialization behavior (ZEND_PROP_PURPOSE_JSON in property array getters) start implementing JsonSerializable, and add implementations of jsonSerialize() returning arrays (e.g. for DateTime, DateTimeZone, DateTimeImmutable, DateTimeZone. (Changing ArrayObject wouldn't make sense, because php users rely on php serializing those with object syntax (e.g. {} instead of [])))

  • 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)

Vote

Voting started 2020-05-13 and ends 2020-05-27.

Vote: Make the JSON extension impossible to disable — Yes: 56 · No: 0 (closed)

Changelog

0.3: Keep the HAVE_JSON constant in config.m4, to avoid a backwards compatibility break.

References

https://externals.io/message/109783 “Moving json extension to core?”

https://externals.io/rfc/jsond

https://wiki.php.net/rfc/permanent_hash_ext