Menu

← Back to function.*

Error Identifier: function.duplicate

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

namespace App;

function helper(): void
{
}

function helper(): void
{
}

Why is it reported? #

The same function name is declared multiple times within the same namespace. PHP does not allow two functions with the same name in the same namespace. When a function is declared more than once, PHP will throw a fatal error at runtime. This usually happens due to copy-paste mistakes, file inclusion issues, or when two files define the same function and are both included in the project.

How to fix it #

Remove the duplicate function declaration, keeping only one:

 <?php declare(strict_types = 1);
 
 namespace App;

 function helper(): void
 {
 }

-function helper(): void
-{
-}

If both declarations are intentionally different, rename one of them:

 <?php declare(strict_types = 1);
 
 namespace App;

 function helper(): void
 {
 }

-function helper(): void
+function helperAlternative(): void
 {
 }

How to ignore this error #

You can use the identifier function.duplicate to ignore this error using a comment:

// @phpstan-ignore function.duplicate
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: function.duplicate

Rules that report this error #

  • PHPStan\Rules\Functions\DuplicateFunctionDeclarationRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.