rfc:userspace_operator_overloading
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:userspace_operator_overloading [2020/03/23 17:11] – jbtronics | rfc:userspace_operator_overloading [2020/04/06 19:31] (current) – jbtronics | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2020-02-01 | * Date: 2020-02-01 | ||
* Author: Jan Böhmer, jan.h.boehmer@gmx.de | * Author: Jan Böhmer, jan.h.boehmer@gmx.de | ||
- | * Status: | + | * Status: |
* Target Version: PHP 8.0 | * Target Version: PHP 8.0 | ||
* Implementation: | * Implementation: | ||
Line 44: | Line 44: | ||
// Equivalent to $x = Vector3:: | // Equivalent to $x = Vector3:: | ||
$x = $a + $b; | $x = $a + $b; | ||
- | // | + | // |
$y = 3 * $b; | $y = 3 * $b; | ||
</ | </ | ||
Line 89: | Line 89: | ||
The following operators can not be overloaded by using this method (neither explicit or implicit): | The following operators can not be overloaded by using this method (neither explicit or implicit): | ||
| ^ Operator | | ^ Operator | ||
- | | Comparision operators | ''<'', | + | | Comparision operators | ''<'', |
| Assignment operator | | Assignment operator | ||
| Logic operators | | Logic operators | ||
Line 96: | Line 96: | ||
| Tenary operator | | Tenary operator | ||
| Error control operator | '' | | Error control operator | '' | ||
- | | Object access operator | '' | + | | Object access operator | '' |
==== Evaluation order ==== | ==== Evaluation order ==== | ||
Line 112: | Line 112: | ||
==== Error handling ==== | ==== Error handling ==== | ||
- | If an operator is used with an object that does not overload this operator, an NOTICE is triggered, which gives the user a hint about the method that has to be overloaded. For backward compatibility objects, which do not overload the operator, are converted to integer 1 (current behavior). | + | If an operator is used with an object that does not overload this operator, an NOTICE is triggered |
If the class overloads the operator, and the magic method do not return a value, an ERROR is triggered. | If the class overloads the operator, and the magic method do not return a value, an ERROR is triggered. | ||
Line 154: | Line 154: | ||
==== Immutable types ==== | ==== Immutable types ==== | ||
- | To ensure that objects can not be changed (which could cause undesirable behavior), immutable objects (see this [[rfc: | + | To ensure that objects can not be changed (which could cause undesirable behavior), immutable objects (see this [[rfc: |
==== Allow overloading of shorthand assignment operators and increment/ | ==== Allow overloading of shorthand assignment operators and increment/ | ||
Line 161: | Line 161: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Add userspace operator overloading as described: yes/no | Add userspace operator overloading as described: yes/no | ||
+ | |||
+ | ===== Vote ===== | ||
+ | Voting started 2020-03-23 and ends 2020-04-06. | ||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
Line 169: | Line 176: | ||
* [[https:// | * [[https:// | ||
* [[rfc: | * [[rfc: | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | ===== Rejectected features ===== | ||
+ | * Use interfaces instead of magic methods | ||
+ | * Use type hints to declare supported types (this would introduce some special kind of function overloading) | ||
===== Changelog ===== | ===== Changelog ===== |
rfc/userspace_operator_overloading.txt · Last modified: 2020/04/06 19:31 by jbtronics