rfc:weakrefs
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:weakrefs [2018/05/17 06:10] – created krakjoe | rfc:weakrefs [2019/03/13 09:31] (current) – krakjoe | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2018-05-17 | * Date: 2018-05-17 | ||
* Author: krakjoe | * Author: krakjoe | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== 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. | + | 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. |
The current implementations of WeakRef all work by overloading object handlers, the most popular implementation ([[https:// | The current implementations of WeakRef all work by overloading object handlers, the most popular implementation ([[https:// | ||
- | Other implementations are possible, [[https:// | + | Other implementations are possible, [[https:// |
- | In principle weak referencing an object is not complicated, | + | In principle weak referencing an object is not complicated, |
===== Proposal ===== | ===== Proposal ===== | ||
We directly support weak referencing in the simplest possible way. | We directly support weak referencing in the simplest possible way. | ||
+ | |||
+ | ===== API ===== | ||
+ | The proposed API: | ||
+ | |||
+ | <code php> | ||
+ | final class WeakReference { | ||
+ | public static function create(object $object) : WeakReference; | ||
+ | | ||
+ | public function get() : ?object; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The proposed API differs from the documented [[http:// | ||
+ | |||
+ | * valid | ||
+ | * acquire | ||
+ | * release | ||
+ | |||
+ | Acquire and release are sugar for get and unset, and valid is simply superfluous since the get method will not throw an exception and null is a falsy value. | ||
+ | |||
+ | ===== Implementation Details ===== | ||
+ | |||
+ | The proposed API: | ||
+ | |||
+ | * is closed | ||
+ | * does not support serialization | ||
+ | * does not support properties | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 22: | Line 49: | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | PHP 7.3 | + | PHP 7.4 |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
Line 48: | Line 75: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Simple Yes/No, requires super majority. | Simple Yes/No, requires super majority. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | Voting started 2019-02-22, ends 2019-03-08. | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | https:// | + | https:// |
===== References ===== | ===== References ===== | ||
- | Links to external references, discussions or RFCs | + | Announce: https:// |
+ | |||
+ | Re-announce: |
rfc/weakrefs.1526537451.txt.gz · Last modified: 2018/05/17 06:10 by krakjoe