implements
keyword PHP-W1008A class can only be able to implement an interface using implements
keyword.
Trying to use implements
keyword to reference anything other than an interface, can result in fatal error.
This issue can be raised for any of the following cases:
// invalid: interface "Email" doesn't exist
class Sendgrid implements Email
{
public function send(): void
{
}
}
inteface Email
{
public function send(): void;
}
// invalid: interface "email" is referenced with incorrect case
class Sendgrid implements email
{
public function send(): void
{
}
}
class Email
{
public function send(): void
{
}
}
// invalid: "Email" is not an interface, it's a class
class Sendgrid implements Email
{
public function send(): void
{
}
}
trait EmailTrait
{
public function send(): void
{
}
}
// invalid: "EmailTrait" is not an interface, it's a trait
class Sendgrid implements EmailTrait
{
public function send(): void
{
}
}
interface Email
{
public function send(): void;
}
class Sendgrid implements Email
{
public function send(): void
{
}
}
Use extends
keyword when trying to include a class inside another class:
class Email
{
public function send(): void
{
}
}
class Sendgrid extends Email
{
public function send(): void
{
parent::send();
}
}
Use use
keyword when trying to include a trait inside a class:
trait EmailTrait
{
public function send(): void
{
}
}
class Sendgrid
{
use EmailTrait;
}
implements
keyword.extends
keyword.