rfc:user_defined_operator_overloads
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:user_defined_operator_overloads [2021/12/09 07:49] – copy edit jordanrl | rfc:user_defined_operator_overloads [2021/12/11 09:34] – typo jordanrl | ||
---|---|---|---|
Line 352: | Line 352: | ||
Any return value larger than 0 will be normalized to 1, and any return value smaller than 0 will be normalized to -1. | Any return value larger than 0 will be normalized to 1, and any return value smaller than 0 will be normalized to -1. | ||
- | The $operandPos argument is omitted as it could only be used for evil e.g. implementing different comparison logic depending on which side its on. Instead of passing $operandPos the engine will multiply the result of the call by (-1) where appropriate: | + | The $operandPos argument is omitted as it could only be used for evil e.g. implementing different comparison logic depending on which side it' |
<code php> | <code php> | ||
Line 418: | Line 418: | ||
These methods need to be updated to ignore the operator methods. Since these are stored internally like any other function on the class entry, they need to be filtered from the results. | These methods need to be updated to ignore the operator methods. Since these are stored internally like any other function on the class entry, they need to be filtered from the results. | ||
- | The reason for removing the operators from this result is because the operator methods are not callable with string literals on the object. Since they cannot be called like a method is, the should be returned with the other methods on a class. | + | The reason for removing the operators from this result is because the operator methods are not callable with string literals on the object. Since they cannot be called like a method is, the should |
== Adding getOperators(), | == Adding getOperators(), | ||
Line 523: | Line 523: | ||
} | } | ||
- | $result = new Money(5, ' | + | $result = new Money(5, ' |
// Type error, Vector2d can't be used as Money | // Type error, Vector2d can't be used as Money | ||
Line 622: | Line 622: | ||
// The rest of the extension' | // The rest of the extension' | ||
</ | </ | ||
+ | |||
+ | To further help extensions support this feature, there are two helper functions: | ||
+ | |||
+ | <code c> | ||
+ | int has_overload = zend_std_has_op_overload(opcode, | ||
+ | |||
+ | zend_function overload_method = zend_std_get_op_overload(opcode, | ||
+ | </ | ||
+ | |||
+ | It is safe to pass any zval pointer to '' | ||
==== To Opcache ==== | ==== To Opcache ==== |
rfc/user_defined_operator_overloads.txt · Last modified: 2022/01/17 01:16 by jordanrl