rfc:weakrefs

This is an old revision of the document!


PHP RFC: Weak References

Introduction

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. They are currently supported in PHP by extension, and used (optionally) by projects such as ZF2.

The current implementations of WeakRef all work by overloading object handlers, the most popular implementation (pecl-weakref) changes stack allocated read only memory and will be rendered unusable by PHP 7.3. Other implementations that change object handlers in some other way also risk faulting and rely on undefined behaviour and casting away constness.

Other implementations are possible, krakjoe/uref is an implementation that uses low level features (mprotect, 0xCC, signals) to implement weakrefs, but at the cost of generating segfaults and protecting memory.

In principle weak referencing an object is not complicated, and only requires the (ab)use of Zend because we do not directly support it.

Proposal

We directly support weak referencing in the simplest possible way.

Backward Incompatible Changes

None

Proposed PHP Version(s)

PHP 7.3

RFC Impact

To SAPIs

None

To Existing Extensions

None

To Opcache

None

New Constants

None

php.ini Defaults

None

Open Issues

None

Unaffected PHP Functionality

All

Proposed Voting Choices

Simple Yes/No, requires super majority.

Patches and Tests

References

rfc/weakrefs.1526537617.txt.gz · Last modified: 2018/05/17 06:13 by krakjoe