Skip to content

Commit 81c94a6

Browse files
committed
[RFC] Always enable JSON support in php 8.0
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.
1 parent 125682f commit 81c94a6

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

ext/json/config.m4

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
PHP_ARG_ENABLE([json],
2-
[whether to enable JavaScript Object Serialization support],
3-
[AS_HELP_STRING([--disable-json],
4-
[Disable JavaScript Object Serialization support])],
5-
[yes])
6-
7-
if test "$PHP_JSON" != "no"; then
8-
AC_DEFINE([HAVE_JSON],1 ,[whether to enable JavaScript Object Serialization support])
9-
1+
dnl HAVE_JSON is always 1 as of php 8.0 and the constant will be removed in the future.
2+
dnl Note that HAVE_JSON was never defined for Windows builds (see config.w32)
3+
AC_DEFINE([HAVE_JSON],1 ,[whether to enable JavaScript Object Serialization support])
104
PHP_NEW_EXTENSION(json,
115
json.c \
126
json_encoder.c \
137
json_parser.tab.c \
148
json_scanner.c,
159
$ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
16-
PHP_INSTALL_HEADERS([ext/json], [php_json.h php_json_parser.h php_json_scanner.h])
17-
PHP_ADD_MAKEFILE_FRAGMENT()
18-
PHP_SUBST(JSON_SHARED_LIBADD)
19-
fi
10+
PHP_INSTALL_HEADERS([ext/json], [php_json.h php_json_parser.h php_json_scanner.h])
11+
PHP_ADD_MAKEFILE_FRAGMENT()

ext/json/config.w32

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
// vim:ft=javascript
22

3-
ARG_ENABLE("json", "JavaScript Object Serialization support", "yes");
3+
EXTENSION('json', 'json.c', false /* never shared */, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
44

5-
if (PHP_JSON != "no") {
6-
EXTENSION('json', 'json.c', PHP_JSON_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
7-
8-
if (!FSO.FileExists("ext/json/json_scanner.c")) {
9-
STDOUT.WriteLine("Generating ext/json/json_scanner.c");
10-
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"));
11-
}
12-
if (!FSO.FileExists("ext/json/json_parser.tab.c")) {
13-
STDOUT.WriteLine("Generating ext/json/json_parser.tab.c");
14-
STDOUT.WriteLine(execute(PATH_PROG("bison") + " --defines -l ext/json/json_parser.y -o ext/json/json_parser.tab.c"));
15-
}
5+
if (!FSO.FileExists("ext/json/json_scanner.c")) {
6+
STDOUT.WriteLine("Generating ext/json/json_scanner.c");
7+
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"));
8+
}
9+
if (!FSO.FileExists("ext/json/json_parser.tab.c")) {
10+
STDOUT.WriteLine("Generating ext/json/json_parser.tab.c");
11+
STDOUT.WriteLine(execute(PATH_PROG("bison") + " --defines -l ext/json/json_parser.y -o ext/json/json_parser.tab.c"));
12+
}
1613

17-
ADD_SOURCES(configure_module_dirname, "json_encoder.c json_parser.tab.c json_scanner.c", "json");
14+
ADD_SOURCES(configure_module_dirname, "json_encoder.c json_parser.tab.c json_scanner.c", "json");
1815

19-
ADD_MAKEFILE_FRAGMENT();
16+
ADD_MAKEFILE_FRAGMENT();
2017

21-
PHP_INSTALL_HEADERS("ext/json/", "php_json.h php_json_parser.h php_json_scanner.h");
22-
}
18+
PHP_INSTALL_HEADERS("ext/json/", "php_json.h php_json_parser.h php_json_scanner.h");

0 commit comments

Comments
 (0)