Created
September 30, 2014 12:21
-
-
Save frankdejonge/c26c8e7b6b6e2cabe56a to your computer and use it in GitHub Desktop.
Call forwarding with interfaces and argument unpacking and the splat operator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| interface SomeInterface | |
| { | |
| public function forwardedCall($argument); | |
| } | |
| class Pre56BreakingInterface implements SomeInterface | |
| { | |
| public function forwardedCall() | |
| { | |
| $arguments = func_get_args(); | |
| $subject = $this->getSubject(); | |
| return call_user_func_array([$subject, 'forwardedCall'], $arguments); | |
| } | |
| } | |
| class Pre56ImplementingInterface implements SomeInterface | |
| { | |
| public function forwardedCall($argument) | |
| { | |
| // $argument is dead code | |
| $arguments = func_get_args(); | |
| $subject = $this->getSubject(); | |
| return call_user_func_array([$subject, 'forwardedCall'], $arguments); | |
| } | |
| } | |
| class ModernPHPImplementation implements SomeInterface | |
| { | |
| public function forwardedCall($argument, ...$trailing) | |
| { | |
| // YAY no dead code. | |
| $subject = $this->getSubject(); | |
| return $subject->forwardedCall($argument, ...$trailing); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment