Since: 7.4

final class WeakReference (View source)

Weak references allow the programmer to retain a reference to an object which does not prevent the object from being destroyed.

They are useful for implementing cache like structures.

Methods

__construct()

This method exists only to disallow instantiation of the WeakReference class. Weak references are to be instantiated with the factory method WeakReference::create().

static WeakReference
create(object $object)

Create a new weak reference.

object|null
get()

Gets a weakly referenced object. If the object has already been destroyed, NULL is returned.

Details

__construct()

This method exists only to disallow instantiation of the WeakReference class. Weak references are to be instantiated with the factory method WeakReference::create().

static WeakReference create(object $object)

Since: 7.4

Create a new weak reference.

Parameters

object $object

Any object.

Return Value

WeakReference

The freshly instantiated object.

object|null get()

Since: 7.4

Gets a weakly referenced object. If the object has already been destroyed, NULL is returned.

Return Value

object|null