diff --git a/runtime/interface.cpp b/runtime/interface.cpp index dcdd1769a0..442836ee78 100644 --- a/runtime/interface.cpp +++ b/runtime/interface.cpp @@ -1544,7 +1544,7 @@ static void save_rpc_query_headers(const tl_query_header_t &header) { } } -static void init_superglobals(const http_query_data &http_data, const rpc_query_data &rpc_data, const job_query_data &job_data) { +static void init_superglobals_impl(const http_query_data &http_data, const rpc_query_data &rpc_data, const job_query_data &job_data) { rpc_parse(rpc_data.data, rpc_data.len); reset_superglobals(); @@ -1802,39 +1802,23 @@ static rpc_query_data empty_rpc_data; static job_query_data empty_job_data; void init_superglobals(php_query_data_ptr data) { - http_query_data *http_data = nullptr; - rpc_query_data *rpc_data = nullptr; - job_query_data *job_data = nullptr; + // init superglobals depending on the request type std::visit([&](auto && arg) { - using T = decltype(arg); + using T = std::decay_t; if constexpr (std::is_same_v) { query_type = QUERY_TYPE_RPC; - - http_data = &empty_http_data; - rpc_data = std::get(data); - job_data = &empty_job_data; + init_superglobals_impl(empty_http_data, *std::get(data), empty_job_data); } else if constexpr (std::is_same_v) { query_type = QUERY_TYPE_HTTP; - - http_data = std::get(data); - rpc_data = &empty_rpc_data; - job_data = &empty_job_data; + init_superglobals_impl(*std::get(data), empty_rpc_data, empty_job_data); } else if constexpr (std::is_same_v) { query_type = QUERY_TYPE_JOB; - - http_data = &empty_http_data; - rpc_data = &empty_rpc_data; - job_data = std::get(data); + init_superglobals_impl(empty_http_data, empty_rpc_data, *std::get(data)); } else { query_type = QUERY_TYPE_CONSOLE; - - http_data = &empty_http_data; - rpc_data = &empty_rpc_data; - job_data = &empty_job_data; + init_superglobals_impl(empty_http_data, empty_rpc_data, empty_job_data); } }, data); - - init_superglobals(*http_data, *rpc_data, *job_data); } double f$get_net_time() { diff --git a/server/php-runner.h b/server/php-runner.h index 9b6d19fdc0..08364a5867 100644 --- a/server/php-runner.h +++ b/server/php-runner.h @@ -114,7 +114,7 @@ class PhpScript { sigjmp_buf timeout_handler{}; script_t *run_main{nullptr}; - php_query_data_ptr data{}; + php_query_data_ptr data{null_query_data_ptr{}}; script_result *res{nullptr}; static void script_context_entrypoint() noexcept;