rfc:allow_casting_closures_into_single-method_interface_implementations

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:allow_casting_closures_into_single-method_interface_implementations [2023/04/25 19:32] nicolasgrekasrfc:allow_casting_closures_into_single-method_interface_implementations [2023/04/25 19:36] (current) nicolasgrekas
Line 90: Line 90:
  
 <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);
 } }
 </code> </code>
Line 102: Line 102:
 } }
  
-function executeOperation(InvokableInterface $operation, int $a, int $b): int { +function executeOperation(OperatorInterface $operator, int $a, int $b): int { 
-    return $operation($a, $b);+    return $operator($a, $b);
 } }
  
Line 168: Line 168:
  
 In this example, an ''UriExpanderInterface'' is defined with an <php>expand()</php> method. In this example, an ''UriExpanderInterface'' is defined with an <php>expand()</php> method.
- 
 3 different implementations of the interface are derived using the <php>castTo()</php> method. 3 different implementations of the interface are derived using the <php>castTo()</php> method.
- 
 Finally, the <php>getExpandedUrl()</php> function is defined, which accepts an implementation of Finally, the <php>getExpandedUrl()</php> function is defined, which accepts an implementation of
 <php>UriExpanderInterface</php> and expands a URI template using the provided implementation. <php>UriExpanderInterface</php> and expands a URI template using the provided implementation.
rfc/allow_casting_closures_into_single-method_interface_implementations.1682451154.txt.gz · Last modified: 2023/04/25 19:32 by nicolasgrekas