Skip to main content

ModuleGlobal

Trait ModuleGlobal 

Source
pub trait ModuleGlobal: Default + 'static {
    // Provided methods
    fn ginit(&mut self) { ... }
    fn gshutdown(&mut self) { ... }
}
Expand description

Trait for types used as PHP module globals.

Requires Default for initialization. Override ginit and gshutdown for custom per-thread (ZTS) or per-module (non-ZTS) lifecycle logic.

§Examples

use ext_php_rs::zend::ModuleGlobal;

#[derive(Default)]
struct MyGlobals {
    request_count: i64,
    max_depth: i32,
}

impl ModuleGlobal for MyGlobals {
    fn ginit(&mut self) {
        self.max_depth = 512;
    }
}

Provided Methods§

Source

fn ginit(&mut self)

Called after the struct is initialized with Default::default().

Use for setup that goes beyond what Default can express. In ZTS mode, called once per thread. In non-ZTS mode, called once at module init.

Source

fn gshutdown(&mut self)

Called before the struct is dropped.

Use for cleanup of external resources. In ZTS mode, called once per thread. In non-ZTS mode, called once at module shutdown.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§