no-inner-function
What it does
Section titled “What it does”Reports a function name() {} statement in the body of a function, method or closure.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”<?phpfunction a() { function b() {} }function c() { $f = function () {}; }class D { function m() { function n() {} } }function e() {}Configuration
Section titled “Configuration”php: lint: rules: no-inner-function: warn # off (default), warn, errorEnabled by the presets: php/phpstan.
Suppress one line with sudsy-disable-next-line no-inner-function in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”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. |