Skip to content

Instantly share code, notes, and snippets.

@frankdejonge
Created September 30, 2014 12:21
Show Gist options
  • Select an option

  • Save frankdejonge/c26c8e7b6b6e2cabe56a to your computer and use it in GitHub Desktop.

Select an option

Save frankdejonge/c26c8e7b6b6e2cabe56a to your computer and use it in GitHub Desktop.
Call forwarding with interfaces and argument unpacking and the splat operator.
<?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