Using Variables

This page covers the three kinds of variables available inside a module — module, object, and local — and how their lifetimes differ.

epesi modules work with three basic types of variables:

  • module variables

  • object variables

  • local variables

The main difference between them is how long they live:

  • Module variables keep their value across each processing cycle, for as long as the module stays initialized (displayed or in use).

  • Object variables live on the class object and are cleared on every processing cycle.

  • Local variables live only inside the function that created them, and are cleared on every processing cycle.

Local and object variables work exactly like they do in plain PHP, so this page focuses on module variables.

To set a module variable, assign it a value:

$this->set_module_variable('<variable name>','<value>');

Retrieve it with:

$this->get_module_variable('<variable name>');

Each module variable is kept separately per module instance, not per module class. You can read and write it anytime from inside a regular (non-static) module function — module variables are inaccessible from static functions.

To share a variable between two modules, so a change in one is visible to the other, use:

$this->share_module_variable('<my variable>', $other_module_instance);

After that call, the other module can retrieve the same value with:

$this->get_module_variable('<variable>');