Skip to content

Instantly share code, notes, and snippets.

@sawadashota
Created October 25, 2017 05:52
Show Gist options
  • Save sawadashota/d7d631923db6f11b9d09c4447656e58e to your computer and use it in GitHub Desktop.
Save sawadashota/d7d631923db6f11b9d09c4447656e58e to your computer and use it in GitHub Desktop.
<?php
interface aInterface
{
public function a();
}
interface bInterface extends aInterface
{
public function b();
}
class C implements aInterface
{
public function a()
{
echo "I'm function a!\n";
}
}
class D implements bInterface
{
public function a()
{
echo "I'm function a!\n";
}
public function b()
{
echo "I'm function b!\n";
}
}
function e(aInterface $a)
{
echo $a->a();
echo "aInterface is implemented!\n\n";
}
function f(bInterface $b)
{
echo $b->a();
echo $b->b();
echo "bInterface is implemented!\n\n";
}
$c = new C();
e($c);
$d = new D();
e($d); // aInterfaceを継承したbInterfaceを引数にしているため、aInterfaceを実装しているといえる
f($d);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment