- json_len = php_stream_copy_to_mem(SG(request_info).request_body, &json_str, PHP_STREAM_COPY_ALL, 0);
+ json = php_stream_copy_to_mem(SG(request_info).request_body, PHP_STREAM_COPY_ALL, 0);
+ }
+
+ if (json) {
+ if (json->len) {
+ zval tmp;
+ long flags = JSON_POST_G(flags);
+
+#ifdef PHP_JSON_THROW_ON_ERROR
+ /* there's no execute data, so we must ensure json_decode() is not throwing */
+ flags &= ~PHP_JSON_THROW_ON_ERROR;
+#endif
+
+ ZVAL_NULL(&tmp);
+ php_json_decode_ex(&tmp, json->val, json->len, flags, PG(max_input_nesting_level));
+
+ switch (Z_TYPE(tmp)) {
+ case IS_OBJECT:
+ case IS_ARRAY:
+ 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;
+ }
+ }
+ zend_string_release(json);