Menu

← Back to function.*

Error Identifier: function.inner

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);

function outer(): void
{
	function inner(): void
	{
		echo 'hello';
	}

	inner();
}

Why is it reported? #

PHP allows declaring named functions inside other functions, but PHPStan does not support analysing them. Inner named functions in PHP have unusual scoping behavior – they are registered in the global scope when the outer function is called, not when the inner function is declared. This makes them difficult to analyse statically.

How to fix it #

Refactor the inner function to an anonymous function (closure):

 <?php declare(strict_types = 1);
 
 function outer(): void
 {
-	function inner(): void
-	{
-		echo 'hello';
-	}
+	$inner = function (): void {
+		echo 'hello';
+	};

-	inner();
+	$inner();
 }

Or move the function to the top level:

 <?php declare(strict_types = 1);
 
+function inner(): void
+{
+	echo 'hello';
+}
+
 function outer(): void
 {
-	function inner(): void
-	{
-		echo 'hello';
-	}
-
 	inner();
 }

How to ignore this error #

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

// @phpstan-ignore function.inner
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.inner

Rules that report this error #

  • PHPStan\Rules\Functions\InnerFunctionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.