Skip to content

no-inner-function

PHPsuspiciousno fixdefault: offphp/phpstan

Reports a function name() {} statement in the body of a function, method or closure.

The inner function is declared when the outer one runs, so it does not exist before the first call, and a second call of the outer function fails with an error that the function is already declared.

To fix, declare the function at the top level, or use a closure.

Reported
<?php
function a() { function b() {} }
function c() { $f = function () {}; }
class D { function m() { function n() {} } }
function e() {}
php:
lint:
rules:
no-inner-function: warn # off (default), warn, error

Enabled by the presets: php/phpstan.

Suppress one line with sudsy-disable-next-line no-inner-function in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
phpstan function.inner partial A named function declared in a function, method or closure.