rfc:allow_casting_closures_into_single-method_interface_implementations
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:allow_casting_closures_into_single-method_interface_implementations [2023/04/25 12:12] – nicolasgrekas | rfc:allow_casting_closures_into_single-method_interface_implementations [2023/04/25 19:36] (current) – nicolasgrekas | ||
---|---|---|---|
Line 87: | Line 87: | ||
==== Example 2: Type-safe alternative to using Closure ==== | ==== Example 2: Type-safe alternative to using Closure ==== | ||
- | Imagine that you have the following function, that takes a closure and two number | + | Imagine that you have the following function, that takes a closure and two numbers |
<code php> | <code php> | ||
- | function executeOperation(Closure $operation, int $a, int $b): int { | + | function executeOperation(Closure $operator, int $a, int $b): int { |
- | return $operation($a, $b); | + | return $operator($a, $b); |
} | } | ||
</ | </ | ||
Line 102: | Line 102: | ||
} | } | ||
- | function executeOperation(InvokableInterface | + | function executeOperation(OperatorInterface |
- | return $operation($a, $b); | + | return $operator($a, $b); |
} | } | ||
Line 168: | Line 168: | ||
In this example, an '' | In this example, an '' | ||
- | |||
3 different implementations of the interface are derived using the < | 3 different implementations of the interface are derived using the < | ||
- | |||
Finally, the < | Finally, the < | ||
< | < |
rfc/allow_casting_closures_into_single-method_interface_implementations.1682424738.txt.gz · Last modified: 2023/04/25 12:12 by nicolasgrekas