]> granicus.if.org Git - php/commitdiff
[RFC] Always enable JSON support in php 8.0
authorTyson Andre <tysonandre775@hotmail.com>
Wed, 29 Apr 2020 22:35:52 +0000 (18:35 -0400)
committerTyson Andre <tysonandre775@hotmail.com>
Wed, 27 May 2020 13:08:43 +0000 (09:08 -0400)
Currently, it's possible to disable the json extension with
`./configure --disable-json` (for historical reasons that no longer apply).
However, JSON is 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 I'd personally find it useful if it was always enabled.

Examples of where this would be useful:

- For internal classes to be able to implement `JsonSerializable`
  which currently requires a hard dependency on the JSON extension.
- For 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)
- So that php-src's own modules, tools and test cases can start using JSON
  if it's a good choice for encoding a value. (same for PECLs)

https://wiki.php.net/rfc/jsond mentions that in PHP 5,

> The current Json Parser 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.

Changes:

- Remove all flags related to JSON such as `configure --disable-json`
- Require that JSON be compiled statically instead of as a shared library

Examples of uses of JSON in various distros
(backwards incompatible changes such as changing packaging are typically
reserved for major versions, and 8.0 is a major version)

- JSON is required by `php-cli` or `php` in ubuntu:
  https://packages.ubuntu.com/focal/php/
- The php-json package has to be installed separately
  from the PHP binary in Fedora repos.

Closes GH-5495

NEWS
UPGRADING
ext/json/config.m4
ext/json/config.w32

diff --git a/NEWS b/NEWS
index aeb5c2712614c0d9af3f67cd9d22a411d6ba2fce..03b5d7415ed0b317b8668501f6fa348429568406 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -73,6 +73,10 @@ PHP                                                                        NEWS
   . Fixed bug #79255 (PHP cannot be compiled with enable JIT).
     (Laruence, Dmitry)
 
+- JSON:
+  . The JSON extension is now an integral part of PHP and cannot be disabled
+    as per RFC: https://wiki.php.net/rfc/always_enable_json (tandre)
+
 - LDAP:
   . Removed deprecated ldap_sort. (mcmic)
 
index 81b945d2045416fa12e0a3ddd02506b0092c615a..cca70bcfee7fa7e4175995db49d935468c10e0f8 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -698,6 +698,10 @@ PHP 8.0 UPGRADE NOTES
   . The function imagegetinterpolation() to get the current interpolation method
     has been added.
 
+- JSON:
+  . The JSON extension cannot be disabled anymore and is always an integral part
+    of any PHP build, similar to the date extension.
+
 - MBString:
   . The Unicode data tables have been updated to version 13.0.0.
 
index 01328d57cc8beac9c088647f8b375e88184274eb..35bb1bf9ce33e094bbea216f467f655b5e70ab76 100644 (file)
@@ -1,19 +1,11 @@
-PHP_ARG_ENABLE([json],
-  [whether to enable JavaScript Object Serialization support],
-  [AS_HELP_STRING([--disable-json],
-    [Disable JavaScript Object Serialization support])],
-  [yes])
-
-if test "$PHP_JSON" != "no"; then
-  AC_DEFINE([HAVE_JSON],1 ,[whether to enable JavaScript Object Serialization support])
-
+dnl HAVE_JSON is always 1 as of php 8.0 and the constant will be removed in the future.
+dnl Note that HAVE_JSON was never defined for Windows builds (see config.w32)
+AC_DEFINE([HAVE_JSON],1 ,[whether to enable JavaScript Object Serialization support])
 PHP_NEW_EXTENSION(json,
          json.c \
          json_encoder.c \
          json_parser.tab.c \
          json_scanner.c,
          $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
-  PHP_INSTALL_HEADERS([ext/json], [php_json.h php_json_parser.h php_json_scanner.h])
-  PHP_ADD_MAKEFILE_FRAGMENT()
-  PHP_SUBST(JSON_SHARED_LIBADD)
-fi
+PHP_INSTALL_HEADERS([ext/json], [php_json.h php_json_parser.h php_json_scanner.h])
+PHP_ADD_MAKEFILE_FRAGMENT()
index 82e470f2eec4b002d3ae85092c542e0cb461a047..e54a9caaf5415972957d8890276120b178e5ee10 100644 (file)
@@ -1,22 +1,18 @@
 // vim:ft=javascript
 
-ARG_ENABLE("json", "JavaScript Object Serialization support", "yes");
+EXTENSION('json', 'json.c', false /* never shared */, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
 
-if (PHP_JSON != "no") {
-       EXTENSION('json', 'json.c', PHP_JSON_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
-
-       if (!FSO.FileExists("ext/json/json_scanner.c")) {
-               STDOUT.WriteLine("Generating ext/json/json_scanner.c");
-               STDOUT.WriteLine(execute(PATH_PROG("re2c") + " -t ext/json/php_json_scanner_defs.h --no-generation-date -bci -o ext/json/json_scanner.c ext/json/json_scanner.re"));
-       }
-       if (!FSO.FileExists("ext/json/json_parser.tab.c")) {
-               STDOUT.WriteLine("Generating ext/json/json_parser.tab.c");
-               STDOUT.WriteLine(execute(PATH_PROG("bison") + " --defines -l ext/json/json_parser.y -o ext/json/json_parser.tab.c"));
-       }
+if (!FSO.FileExists("ext/json/json_scanner.c")) {
+    STDOUT.WriteLine("Generating ext/json/json_scanner.c");
+    STDOUT.WriteLine(execute(PATH_PROG("re2c") + " -t ext/json/php_json_scanner_defs.h --no-generation-date -bci -o ext/json/json_scanner.c ext/json/json_scanner.re"));
+}
+if (!FSO.FileExists("ext/json/json_parser.tab.c")) {
+    STDOUT.WriteLine("Generating ext/json/json_parser.tab.c");
+    STDOUT.WriteLine(execute(PATH_PROG("bison") + " --defines -l ext/json/json_parser.y -o ext/json/json_parser.tab.c"));
+}
 
-       ADD_SOURCES(configure_module_dirname, "json_encoder.c json_parser.tab.c json_scanner.c", "json");
+ADD_SOURCES(configure_module_dirname, "json_encoder.c json_parser.tab.c json_scanner.c", "json");
 
-       ADD_MAKEFILE_FRAGMENT();
+ADD_MAKEFILE_FRAGMENT();
 
-       PHP_INSTALL_HEADERS("ext/json/", "php_json.h php_json_parser.h php_json_scanner.h");
-}
+PHP_INSTALL_HEADERS("ext/json/", "php_json.h php_json_parser.h php_json_scanner.h");