rfc:operator-overloading

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:operator-overloading [2016/01/03 01:50] – created pollitarfc:operator-overloading [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== PHP RFC: Your Title Here ======+====== PHP RFC: Operator Overloading ======
   * Version: 0.1   * Version: 0.1
   * Date: 2016-01-02   * Date: 2016-01-02
-  * Author: @pmtarantino, (with Sara Golemon <pollita@php.net>)+  * Author: Patricio Tarantino <patriciotarantino@gmail.com> (with Sara Golemon <pollita@php.net>)
   * Status: Draft   * Status: Draft
   * First Published at: http://wiki.php.net/rfc/operator-overloading   * First Published at: http://wiki.php.net/rfc/operator-overloading
Line 52: Line 52:
   public function __mul($__value__); // Overloads * operator   public function __mul($__value__); // Overloads * operator
   public function __div($__value__); // Overloads / operator   public function __div($__value__); // Overloads / operator
 +  public function __pow($__value__); // Overloads ** operator
 +  public function __concat($__value__); // Overloads . operator
 +
 +===== Opcache =====
 +The implementation of this RFC would add new zend_function pointers to user-defined zend_class_entry structures which opcaches would need to set upon rematerializations.
 +
 +===== Proposed PHP Version(s) =====
 +7.1
 +
 +===== Associativity =====
 +When both operands to a binary expression implement operator overloading, the left-hand operand's handler will be invoked.  If only one of the two implement overloading, then that side is invoked with the relative operation inverted as necessary.  For example **(4 < $complex)** would invoke the is_greater handler for the **$complex** object passing in **4** as though it were the RHS expression.
 +
 +===== Open questions for discussion =====
 +Introduce interface(s) (a la ArrayAccess)?
 +
 +===== Proposed Voting Choices =====
 +Implement user-space operator overloading as described. Requires 2/3 majority.
 +
 +===== Future Expansion =====  
 +Introduce dispatch for additional operations?
 +
   public function __mod($__value__); // Overloads % operator   public function __mod($__value__); // Overloads % operator
   public function __sl($__value__); // Overloads << operator   public function __sl($__value__); // Overloads << operator
   public function __sr($__value__); // Overloads >> operator   public function __sr($__value__); // Overloads >> operator
-  public function __concat($__value__); // Overloads . operator 
   public function __or($__value__); // Overloads | operator   public function __or($__value__); // Overloads | operator
   public function __and($__value__); // Overloads &   public function __and($__value__); // Overloads &
Line 76: Line 96:
   public function __assign_concat($__value__); // Overloads .=   public function __assign_concat($__value__); // Overloads .=
   public function __assign_or($__value__); // Overloads |=   public function __assign_or($__value__); // Overloads |=
-  public function __assign_and($__value__); // Overloads =&+  public function __assign_and($__value__); // Overloads &=
   public function __assign_xor($__value__); // Overloads ^=   public function __assign_xor($__value__); // Overloads ^=
 +  public function __assign_pos($__value__); // Overloads **=
   public function __pre_inc(); // Overloads ++$value   public function __pre_inc(); // Overloads ++$value
   public function __pre_dec(); // Overloads --$value   public function __pre_dec(); // Overloads --$value
Line 83: Line 104:
   public function __post_dec(); // Overloads $value--   public function __post_dec(); // Overloads $value--
  
-===== Proposed PHP Version(s) ===== +==== Limiting Issue: Greater/Lesser are not distinct =====
-7.1 +
- +
-===== Opcache ===== +
-The implementation of this RFC would add new zend_function pointers to user-defined zend_class_entry structures which opcaches would need to set upon rematerializations. +
- +
-===== Limiting Issue: Greater/Lesser are not distinct =====+
 Greater-than, and Greater-than-or-equal expressions are currently implemented by the compiler as inverted Less-than, and Less-than-or-equal expressions.  The implementation of this RFC would need to either exclude the is_greater* functions, or it would need to implement is_greater in the runtime as a distinct expression from is_smaller. Greater-than, and Greater-than-or-equal expressions are currently implemented by the compiler as inverted Less-than, and Less-than-or-equal expressions.  The implementation of this RFC would need to either exclude the is_greater* functions, or it would need to implement is_greater in the runtime as a distinct expression from is_smaller.
- 
-===== Associativity ===== 
-When both operands to a binary expression implement operator overloading, the left-hand operand's handler will be invoked.  If only one of the two implement overloading, then that side is invoked with the relative operation inverted as necessary.  For example **(4 < $complex)** would invoke the is_greater handler for the **$complex** object passing in **4** as though it were the RHS expression. 
- 
-===== Open questions for discussion ===== 
-  # Update the engine to disambiguate is greater from is lesser? 
-  # Introduce interface(s) (a la ArrayAccess) 
- 
-===== Proposed Voting Choices ===== 
-Implement user-space operator overloading as described. Requires 2/3 majority. 
  
 ===== References ===== ===== References =====
 https://github.com/php/pecl-php-operator exists as an extension based approach to operator overloading.  A formal in-tree implementation would merit a new implementation in std_object_handlers. https://github.com/php/pecl-php-operator exists as an extension based approach to operator overloading.  A formal in-tree implementation would merit a new implementation in std_object_handlers.
  
rfc/operator-overloading.1451785815.txt.gz · Last modified: 2017/09/22 13:28 (external edit)