Skip to content

Instantly share code, notes, and snippets.

@cursedcoder
Last active December 14, 2015 04:19
Show Gist options
  • Save cursedcoder/5027008 to your computer and use it in GitHub Desktop.
Save cursedcoder/5027008 to your computer and use it in GitHub Desktop.

Good:

interface MyInterface
{
  function foo();
}

class MyClass implements MyInterface
{
  public function foo($a = null, $b = null)
  {
    echo $a + $b;
  }
}

$class = new MyClass();
$class->foo(2, 2);

Result:

4

Bad:

interface MyInterface
{
  function foo();
}

class MyClass implements MyInterface
{
  public function foo($a, $b)
  {
    echo $a + $b;
  }
}

$class = new MyClass();
$class->foo(2, 2);

Result:

Fatal error: Declaration of MyClass::foo() must be compatible with MyInterface::foo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment