rfc:weakrefs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:weakrefs [2018/05/17 07:17]
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: Discussion+  * Status: Implemented
   * First Published at: http://wiki.php.net/rfc/weakrefs   * First Published at: http://wiki.php.net/rfc/weakrefs
  
Line 11: Line 11:
 The current implementations of WeakRef all work by overloading object handlers, the most popular implementation ([[https://github.com/colder/php-weakref|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. The current implementations of WeakRef all work by overloading object handlers, the most popular implementation ([[https://github.com/colder/php-weakref|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, [[https://github.com/krakjoe/uref|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.+Other implementations are possible, [[https://github.com/krakjoe/uref|krakjoe/uref]] is an implementation that uses low level features (mprotect, 0xCC, signals) to implement weakrefs, but at the cost of portability, generating segfaultsprotecting memory, and implicit signal handler restrictions.
  
 In principle weak referencing an object is not complicated, and only requires the (ab)use of Zend or layers beneath because we do not directly support it. In principle weak referencing an object is not complicated, and only requires the (ab)use of Zend or layers beneath because we do not directly support it.
Line 17: Line 17:
 ===== 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;
 +}
 +</code>
 +
 +The proposed API differs from the documented [[http://docs.php.net/class.weakref|WeakRef]] class. The currently documented API includes the following methods omitted from the proposed API:
 +
 +  * 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="Implement weakrefs ?" auth="krakjoe" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
 +
 +Voting started 2019-02-22, ends 2019-03-08.
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
-https://github.com/php/php-src/pull/3237+https://github.com/php/php-src/pull/3787
  
 ===== References ===== ===== References =====
-https://externals.io/message/102111+Announce: https://externals.io/message/102111 
 + 
 +Re-announce: https://externals.io/message/104014
rfc/weakrefs.1526541463.txt.gz · Last modified: 2018/05/17 07:17 by krakjoe