Luminova Framework

PHP Luminova: Runtime Shared Memory

Last updated: 2026-11-28 20:57:12

Store and retrieve temporary values within one PHP runtime.

Use Luminova\Runtime to share temporary keyed values among code running in the same PHP process. The storage is in memory and ends with the PHP runtime. For a long-running CLI process, values remain available until they are removed or the process exits.


Usages

use Luminova\Runtime;

// Store a value
Runtime::set('theme', 'dark');

// Get a value
$theme = Runtime::get('theme') ?? 'light';

// Check if it exists
if (Runtime::has('theme')) {
    // ...
}

// Remove one value
Runtime::remove('theme');

// Clear everything
Runtime::clear();

// Count how many keys are stored
$count = Runtime::count();

Reuse a Value Within the Same Runtime

Use shared() to initialize a value in one part of the application and read it in another. The named default argument supplies a fallback on reads.

use Luminova\Runtime;
use function Luminova\Funcs\shared;

shared('catalog.locale', 'en');
$locale = shared('catalog.locale', default: 'en');

Runtime::remove('catalog.locale');

Class Definition

  • Full namespace: Luminova\Runtime
  • This class is final.

See Also:

  • Luminova\Funcs\shared() - Global helper for quick access.

Shared Memory Methods

set

Set a shared value.

Stores the value. If both the new and existing values are arrays, matching keys are replaced.

public static function set(string $key, mixed $value): mixed

Parameters:

ParameterTypeDescription
$keystringThe key to store the value under.
$valuemixedThe value to store.

Return:

mixed - Returns the stored value.


get

Get a shared value.

Retrieves a value stored under the specified key.

public static function get(string $key): mixed

Parameters:

ParameterTypeDescription
$keystringThe key to retrieve.

Return:

mixed - Returns the stored value or null if not found.

Note:This method returns null if the key does not exist.


has

Check if a key exists in the shared storage.

public static function has(string $key): bool

Parameters:

ParameterTypeDescription
$keystringThe key to check.

Return:

bool - Return true if the key exists, false otherwise.


remove

Remove a key from the shared storage.

public static function remove(string $key, bool $userDefined = true): void

Parameters:

ParameterTypeDescription
$keystringKey to remove.
$userDefinedboolProtect framework-reserved keys (default true).

clear

Clear application-defined keys. Framework-reserved entries remain.

public static function clear(): void

count

Count all stored keys, including framework entries.

public static function count(): int

Return:

int - Return the number of stored keys.


add

Assign one entry inside a shared array. The method initializes an absent or null storage key to an empty array. Use this method with an array-valued key.

public static function add(string $key, string|int $index, mixed $value): mixed

Parameters:

ParameterTypeDescription
$keystringShared storage key.
$indexstring\|intIndex to set.
$valuemixedValue to store.

Return:

mixed - Returns the stored value.