@@ -13,11 +13,12 @@ use crate::exception::PhpResult;
13
13
#[ cfg( php82) ]
14
14
use crate :: ffi:: zend_atomic_bool_store;
15
15
use crate :: ffi:: {
16
- _sapi_module_struct, _zend_executor_globals, ext_php_rs_executor_globals,
17
- ext_php_rs_file_globals, ext_php_rs_process_globals, ext_php_rs_sapi_globals,
18
- ext_php_rs_sapi_module, php_core_globals, php_file_globals, sapi_globals_struct,
19
- sapi_header_struct, sapi_headers_struct, sapi_request_info, zend_ini_entry,
20
- zend_is_auto_global, TRACK_VARS_COOKIE , TRACK_VARS_ENV , TRACK_VARS_FILES , TRACK_VARS_GET ,
16
+ _sapi_module_struct, _zend_executor_globals, _zend_known_string_id_ZEND_STR_AUTOGLOBAL_REQUEST,
17
+ executor_globals, ext_php_rs_executor_globals, ext_php_rs_file_globals,
18
+ ext_php_rs_process_globals, ext_php_rs_sapi_globals, ext_php_rs_sapi_module, php_core_globals,
19
+ php_file_globals, sapi_globals_struct, sapi_header_struct, sapi_headers_struct,
20
+ sapi_request_info, zend_hash_find_known_hash, zend_ini_entry, zend_is_auto_global,
21
+ zend_known_strings, TRACK_VARS_COOKIE , TRACK_VARS_ENV , TRACK_VARS_FILES , TRACK_VARS_GET ,
21
22
TRACK_VARS_POST , TRACK_VARS_SERVER ,
22
23
} ;
23
24
@@ -285,16 +286,24 @@ impl ProcessGlobals {
285
286
/// Get the HTTP Request variables. Equivalent of $_REQUEST.
286
287
///
287
288
/// # Panics
288
- /// There is an outstanding issue with the implementation of this function.
289
- /// Untill resolved, this function will allways panic.
290
- ///
291
- /// - <https://github.com/davidcole1340/ext-php-rs/issues/331>
292
- /// - <https://github.com/php/php-src/issues/16541>
293
- pub fn http_request_vars ( & self ) -> & ZendHashTable {
294
- todo ! ( "$_REQUEST super global was erroneously fetched from http_globals which resulted in an out-of-bounds access. A new implementation is needed." ) ;
295
- // self.http_globals[TRACK_VARS_REQUEST as usize]
296
- // .array()
297
- // .expect("Type is not a ZendArray")
289
+ /// - If the request global is not found or fails to be populated.
290
+ /// - If the request global is not a ZendArray.
291
+ pub fn http_request_vars ( & self ) -> Option < & ZendHashTable > {
292
+ let key = unsafe {
293
+ * zend_known_strings. add ( _zend_known_string_id_ZEND_STR_AUTOGLOBAL_REQUEST as usize )
294
+ } ;
295
+
296
+ // `$_REQUEST` is lazy-initted, we need to call `zend_is_auto_global` to make sure it's populated.
297
+ if !unsafe { zend_is_auto_global ( key) } {
298
+ panic ! ( "Failed to get request global" ) ;
299
+ }
300
+
301
+ let request = unsafe { zend_hash_find_known_hash ( & executor_globals. symbol_table , key) } ;
302
+ if request. is_null ( ) {
303
+ return None ;
304
+ }
305
+
306
+ Some ( unsafe { ( * request) . array ( ) } . expect ( "Type is not a ZendArray" ) )
298
307
}
299
308
300
309
/// Get the HTTP Environment variables. Equivalent of $_ENV.
0 commit comments