X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-json_post;a=blobdiff_plain;f=php_json_post.c;h=c2e5ba69eabb4618b45c5c541a451472d351c959;hp=cb8a53b65586afdd2a03d6ed71e430c6820421b3;hb=87da3f6139e8bea190638456477055db6d20a6eb;hpb=8cdbdf67d395c318c1bd75867c8d504211df68cc diff --git a/php_json_post.c b/php_json_post.c index cb8a53b..c2e5ba6 100644 --- a/php_json_post.c +++ b/php_json_post.c @@ -63,13 +63,18 @@ static SAPI_POST_HANDLER_FUNC(php_json_post_handler) ZVAL_NULL(&tmp); - php_json_decode(&tmp, json->val, json->len, JSON_POST_G(flags), PG(max_input_nesting_level)); + php_json_decode_ex(&tmp, json->val, json->len, JSON_POST_G(flags), PG(max_input_nesting_level)); switch (Z_TYPE(tmp)) { case IS_OBJECT: case IS_ARRAY: - zval_dtor(arg); - ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_POST], &tmp); + if (zend_hash_num_elements(HASH_OF(&tmp))) { + zval_dtor(arg); + ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_POST], &tmp); + } else { + /* PHP-7.4 optimizes empty array */ + zval_ptr_dtor(&tmp); + } break; default: break; @@ -130,14 +135,16 @@ static SAPI_POST_HANDLER_FUNC(php_json_post_handler) PHP_MINIT_FUNCTION(json_post) { - sapi_post_entry entry = {NULL, 0, NULL, NULL}; - - entry.post_reader = sapi_read_standard_form_data; - entry.post_handler = php_json_post_handler; - - entry.content_type = "text/json"; - entry.content_type_len = sizeof("text/json")-1; - sapi_register_post_entry(&entry TSRMLS_CC); + sapi_post_entry json_post_entries[] = { + { "text/json", sizeof("text/json")-1, sapi_read_standard_form_data, php_json_post_handler }, + { "application/json", sizeof("application/json")-1, sapi_read_standard_form_data, php_json_post_handler }, + { NULL, 0, NULL, NULL } + }; + +#ifndef TSRMLS_CC +# define TSRMLS_CC +#endif + sapi_register_post_entries(json_post_entries TSRMLS_CC); ZEND_INIT_MODULE_GLOBALS(json_post, php_json_post_init_globals, NULL); REGISTER_INI_ENTRIES();