Luminova Framework

PHP Luminova: Store a Value with the WeakReference Utility

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

Store, replace, or read a value through a reusable wrapper.

Luminova’s WeakReference is a mutable value holder. It keeps a regular PHP reference to a stored object for as long as that object remains in the wrapper. To release the stored value, replace it with null. PHP’s built-in \WeakReference provides garbage-collection-aware object references.


Usage

use Luminova\Utility\Reference\WeakReference;

$reference = new WeakReference('draft');
$reference->setValue('published');

echo $reference->getValue(); // published

$reference->setValue(null);

Class Definition

  • Full namespace: Luminova\Utility\Reference\WeakReference
  • This class is final.

Methods

__construct

Create a holder with an optional initial value.

public function __construct(mixed $reference = null)

Parameters:

ParameterTypeDescription
$referencemixedInitial value to store (default: null).

setValue

Replace the stored value. Pass null to clear it.

public function setValue(mixed $reference): self

Parameters:

ParameterTypeDescription
$referencemixedNew value to store.

Return:

self - The same wrapper instance.


getValue

Read the current stored value.

public function getValue(): mixed

Return:

mixed - The stored value, which may be null.