Skip to content

Instantly share code, notes, and snippets.

@alcaeus
Last active November 25, 2016 16:01
Show Gist options
  • Save alcaeus/8dd2d4ca3be37f9ca7d2009cd644ad84 to your computer and use it in GitHub Desktop.
Save alcaeus/8dd2d4ca3be37f9ca7d2009cd644ad84 to your computer and use it in GitHub Desktop.
Extending interfaces
<?php
declare(strict_types = 1);
class FooImplementation implements FooInterface
{
// Note: this throws an error in PHP 7.1:
// Declaration of FooImplementation::doSomething(): FooImplementation must be compatible with FooInterface::doSomething(): FooInterface
public function doSomething(): FooImplementation
{
return $this;
}
}
<?php
declare(strict_types = 1);
interface FooInterface
{
public function doSomething(): FooInterface;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment