pub struct ModuleGlobals<T: ModuleGlobal> { /* private fields */ }Expand description
Thread-safe handle to PHP module globals.
Declare as a static and pass to ModuleBuilder::globals().
In ZTS (thread-safe) builds, PHP’s TSRM allocates per-thread storage and manages the lifetime via GINIT/GSHUTDOWN callbacks. In non-ZTS builds, the globals live inline in this struct as a plain static.
§Examples
use ext_php_rs::zend::{ModuleGlobal, ModuleGlobals};
#[derive(Default)]
struct MyGlobals {
counter: i64,
}
impl ModuleGlobal for MyGlobals {}
static MY_GLOBALS: ModuleGlobals<MyGlobals> = ModuleGlobals::new();Implementations§
Source§impl<T: ModuleGlobal> ModuleGlobals<T>
impl<T: ModuleGlobal> ModuleGlobals<T>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an uninitialized globals handle.
Must be passed to ModuleBuilder::globals()
for PHP to allocate and initialize the storage.
Sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Returns a shared reference to the current thread’s globals.
Safe because PHP guarantees single-threaded request processing: only one request handler runs per thread at a time, and module globals are initialized before any request begins.
§Panics
Debug-asserts that the globals have been registered. In release builds, calling this before module init is undefined behavior.