website/errors/method.nonAbstract.md
<?php declare(strict_types = 1);
class HelloWorld
{
public function sayHello(): void;
}
A non-abstract method in a non-abstract class is declared without a body. In PHP, only abstract methods in abstract classes or interfaces can omit the method body. A concrete method in a concrete class must have a body with an implementation, even if the body is empty.
This is a compile-time error in PHP and the code will not run.
Add a method body:
class HelloWorld
{
- public function sayHello(): void;
+ public function sayHello(): void
+ {
+ // implementation
+ }
}
If the method is meant to be abstract, declare both the method and the class as abstract:
-class HelloWorld
+abstract class HelloWorld
{
- public function sayHello(): void;
+ abstract public function sayHello(): void;
}