rfc:user_defined_operator_overloads
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:user_defined_operator_overloads [2021/12/12 01:14] – Expanded non-callable section jordanrl | rfc:user_defined_operator_overloads [2022/01/17 01:16] (current) – closed voting jordanrl | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2021-08-14 | * Date: 2021-08-14 | ||
* Author: Jordan LeDoux, jordan.ledoux@gmail.com | * Author: Jordan LeDoux, jordan.ledoux@gmail.com | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 101: | Line 101: | ||
This is avoided by allowing the restrictions on operator names to be separated from the restrictions on function names. | This is avoided by allowing the restrictions on operator names to be separated from the restrictions on function names. | ||
- | === Non-Callable === | + | === Callable === |
- | Operand implementations | + | Operand implementations |
<code php> | <code php> | ||
- | // These all should result in an error | + | // These all will work normally |
+ | $op = ' | ||
+ | $callable = [$obj, ' | ||
+ | |||
+ | // Calls on the object variable | ||
$obj-> | $obj-> | ||
+ | $obj-> | ||
+ | $callable(1, | ||
+ | |||
+ | // Calls using call_user_func | ||
call_user_func([$obj, | call_user_func([$obj, | ||
+ | call_user_func($callable, | ||
+ | |||
+ | // This will error since + is not static | ||
call_user_func(' | call_user_func(' | ||
</ | </ | ||
- | They can be directly invoked with a Closure however. This is to fully support | + | They can be also be directly invoked with a Closure however. This fully supports |
<code php> | <code php> | ||
Line 671: | Line 682: | ||
==== Global Operator Overloads ==== | ==== Global Operator Overloads ==== | ||
This RFC deals with allowing each class to define its own interaction with operators. However, if overloading the operator itself were desired for the entire application, | This RFC deals with allowing each class to define its own interaction with operators. However, if overloading the operator itself were desired for the entire application, | ||
+ | |||
+ | ==== Functions for Operators ==== | ||
+ | Having functions for operators may be beneficial when objects which use operator overloads are used in conjunction with functions like '' | ||
+ | |||
+ | <code php> | ||
+ | array_reduce($arrOfObjs, | ||
+ | </ | ||
+ | |||
+ | These could be polyfilled in PHP currently: | ||
+ | |||
+ | <code php> | ||
+ | array_reduce($arrOfObjs, | ||
+ | </ | ||
+ | |||
+ | ==== Query Builder Improvements ==== | ||
+ | With some additional improvements, | ||
+ | |||
+ | <code php> | ||
+ | $qb-> | ||
+ | </ | ||
==== Enum Return Type For <=> ==== | ==== Enum Return Type For <=> ==== | ||
Line 682: | Line 713: | ||
It is listed as a separate RFC because it is something that could be delivered whether or not this RFC passes. | It is listed as a separate RFC because it is something that could be delivered whether or not this RFC passes. | ||
- | |||
- | ===== Proposed Voting Choices ===== | ||
- | Add limited user-defined operator overloads as described: yes/no. A 2/3 vote is required to pass. | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
Line 696: | Line 724: | ||
- a link to the language specification section (if any) | - a link to the language specification section (if any) | ||
- | ===== References | + | ===== Proposed Voting Choices |
+ | Add limited user-defined operator overloads as described: yes/no. A 2/3 vote is required to pass. | ||
+ | |||
+ | ===== Vote ===== | ||
+ | |||
+ | Voting started 2022-01-03 at 00:15 UTC and will end 2022-01-17 at 00:15 UTC. | ||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Changelog ===== | ===== Changelog ===== |
rfc/user_defined_operator_overloads.1639271652.txt.gz · Last modified: 2021/12/12 01:14 by jordanrl