PHP fatal error: your class has abstract methods it does not implement (Symfony)
Class must be declared abstract or implement the remaining methodsShort answer
PHP raises this fatal error when a class implements an interface or extends an abstract class but one required method is missing, or is declared with a signature that does not match. The error names the missing method in brackets. Add that method with a compatible signature, or mark the class abstract if it is only a base class.
Fix it fast
1Find out which cause you have
Read the part of the message in brackets: it is Interface::method or ParentClass::method. That is the method PHP cannot find. Then list what your class already declares.
php -l src/Entity/User.php grep -n "function \|implements\|extends" src/Entity/User.php2Match what you see, then jump to its fix
- 1
the bracket names UserInterface::getUserIdentifier, getRoles or PasswordAuthenticatedUserInterface::getPasswordA Symfony User class lacks a method that UserInterface requiresFix - 2
the bracket names AbstractSomething::method, a class that is yours or from a vendor packageA child class does not define every abstract method of its parentFix - 3
the same fatal error right after a package upgrade, although a method with that name existsThe method exists but its signature is not compatibleFix
- 1
What does the error look like?
Class must be declared abstract or implement the remaining methods
Cause 1 of 3
A Symfony User class lacks a method that UserInterface requires
1Check
Symfony asks a user class to implement UserInterface, and PasswordAuthenticatedUserInterface when passwords are stored. The generated class provides getUserIdentifier(), getRoles() and getPassword(). A class written for an older release, or edited by hand, often lacks one of them.
grep -n "getUserIdentifier\|getRoles\|getPassword" src/Entity/User.php2Fix
Add the missing method. For a class that uses an email as the login, getUserIdentifier() returns that email as a string. Regenerating a fresh class with the maker command and comparing it with yours shows every method that is expected.
public function getUserIdentifier(): string
{
return (string) $this->email;
}
# to see the reference version:
php bin/console make:user3Verify
Lint the file and clear the cache; the fatal error is gone.
php -l src/Entity/User.php
php bin/console cache:clearConfirmed by symfony.com
Cause 2 of 3
A child class does not define every abstract method of its parent
1Check
Open the parent class and find the methods marked abstract. PHP requires the child to define all of them. A class with even one abstract method must itself be abstract.
grep -n "abstract " vendor/vendor-name/package-name/src/ParentClass.php2Fix
Implement each abstract method in the child class. If the class is only meant to be extended, declare it abstract instead of implementing anything.
abstract class BaseReport
{
abstract protected function build(): array;
}
final class SalesReport extends BaseReport
{
protected function build(): array
{
return [];
}
}3Verify
Load the class once so PHP compiles it.
php -l src/Report/SalesReport.php && php -r 'require "vendor/autoload.php"; new App\Report\SalesReport();'Confirmed by php.net
Cause 3 of 3
The method exists but its signature is not compatible
1Check
The manual says implemented abstract methods must follow the usual inheritance and signature compatibility rules. A different parameter list, or a changed return type breaks the match.
grep -n "function build" vendor/vendor-name/package-name/src/ParentClass.php
grep -n "function build" src/Report/SalesReport.php2Fix
Copy the parameter list, visibility and return type from the parent declaration. A child may add optional parameters, but may not remove or retype the required ones.
// parent: abstract protected function prefixName($name);
public function prefixName($name, $separator = ".")
{
return $name . $separator;
}3Verify
Lint the file again.
php -l src/Report/SalesReport.phpConfirmed by php.net
How do I stop it coming back?
- Generate user classes with the maker command instead of copying one from an older project.
- After a Composer upgrade, read the changelog of any package whose interface or abstract class you implement.
- Add return types to methods you write, so a mismatch shows up in your editor before it reaches the server.
- Run php -l and your test suite in CI on every pull request.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix