static-closureClosure declared static, which is the one that cannot be bound to an
object and so can never touch $this. Unlike purity this is written in the
syntax, so an analyzer has no excuse for missing it — the probe is an
ordinary closure, identical but for the keyword.
References:
- PHPStan TypeNodeResolver static-closure resolves to ClosureType(isStatic: yes)| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 | Unrecognized | phpdoc_advanced_fallback_static_closure.php:20: Saw a token Phan may have failed to parse after '* @return static-closure': after static, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_static_closure.php:22: Return type of returnsStaticClosure() is undeclared type static [PhanUndeclaredTypeReturnType] phpdoc_advanced_fallback_static_closure.php:24: Returning (fn) of type Closure():int but returnsStaticClosure() is declared to return static (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal] phpdoc_advanced_fallback_static_closure.php:32: Saw possibly unextractable annotation for a fragment of comment '* @param static-closure $value': after static, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName] phpdoc_advanced_fallback_static_closure.php:32: Saw a token Phan may have failed to parse after '* @param static-closure $value': after static, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_static_closure.php:34: Parameter $value has undeclared type static [PhanUndeclaredTypeParameter] phpdoc_advanced_fallback_static_closure.php:39: Argument 1 ($value) is returnsStaticClosure() of type static but \Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsClosure() takes \Closure defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_static_closure.php:27 [PhanTypeMismatchArgument] phpdoc_advanced_fallback_static_closure.php:42: Argument 1 ($value) is (fn) of type Closure():int but \Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure() takes static (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_static_closure.php:34 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_static_closure.php:45: Argument 1 ($value) is (fn) of type Closure():int but \Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure() takes static (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_static_closure.php:34 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_static_closure.php:48: Argument 1 ($value) is 'strlen' of type string but \Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure() takes static (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_static_closure.php:34 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
Expectation diffLine 24: Expected valid value to be accepted, got ["Returning (fn) of type Closure():int but returnsStaticClosure() is declared to return static (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal]"] Line 39: Expected valid value to be accepted, got ["Argument 1 ($value) is returnsStaticClosure() of type static but \\Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\acceptsClosure() takes \\Closure defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_static_closure.php:27 [PhanTypeMismatchArgument]"] Line 42: Expected valid value to be accepted, got ["Argument 1 ($value) is (fn) of type Closure():int but \\Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\acceptsStaticClosure() takes static (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_static_closure.php:34 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"] |
| phpstan | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced reported Lv.5+ | phpdoc_advanced_fallback_static_closure.php:45: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure expects static-Closure, Closure(): 1 given. [identifier=argument.type] [reported-from-level=5] phpdoc_advanced_fallback_static_closure.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure expects static-Closure, 'strlen' given. [identifier=argument.type] [reported-from-level=5] With strict-rulesphpdoc_advanced_fallback_static_closure.php:45: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure expects static-Closure, Closure(): 1 given. [identifier=argument.type] phpdoc_advanced_fallback_static_closure.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure expects static-Closure, 'strlen' given. [identifier=argument.type]
|
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Unrecognized (pzoom≠) | phpdoc_advanced_fallback_static_closure.php:22: Unrecognized type Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure in docblock for Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\returnsStaticClosure [InvalidDocblock] phpdoc_advanced_fallback_static_closure.php:22: Method Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\returnsStaticClosure does not have a return type, expecting pure-Closure():1 [MissingReturnType] phpdoc_advanced_fallback_static_closure.php:32: Unrecognized type Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure in docblock for Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure [InvalidDocblock] phpdoc_advanced_fallback_static_closure.php:34: Parameter $value has no provided type [MissingParamType] phpdoc_advanced_fallback_static_closure.php:39: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsClosure cannot be mixed, expecting Closure [MixedArgument] pzoom (Psalm port)phpdoc_advanced_fallback_static_closure.php:22: Invalid return docblock type [InvalidDocblock] phpdoc_advanced_fallback_static_closure.php:22: Function Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\returnsStaticClosure does not have a return type [MissingReturnType] phpdoc_advanced_fallback_static_closure.php:34: Invalid docblock type [InvalidDocblock] phpdoc_advanced_fallback_static_closure.php:34: Argument $value of Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure does not have a type [MissingParamType] phpdoc_advanced_fallback_static_closure.php:39: Argument 1 of acceptsClosure cannot be mixed, expecting Closure [MixedArgument]
Expectation diffLine 39: Expected valid value to be accepted, got ["Argument 1 of Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\acceptsClosure cannot be mixed, expecting Closure [MixedArgument]"] |
| mago | 1.46.0mago 1.46.0 | Unrecognized | phpdoc_advanced_fallback_static_closure.php:20: Cannot find class, interface, enum, or type alias `Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure`. [non-existent-class-like]
phpdoc_advanced_fallback_static_closure.php:24: Invalid return type for function `Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\returnsStaticClosure`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure)`, but found `(closure(): int(1))`. [invalid-return-statement]
phpdoc_advanced_fallback_static_closure.php:32: Cannot find class, interface, enum, or type alias `Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure`. [non-existent-class-like]
phpdoc_advanced_fallback_static_closure.php:39: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsClosure`: expected `(closure(...mixed=): mixed)`, but found `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure)`. [invalid-argument]
phpdoc_advanced_fallback_static_closure.php:42: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure)`, but found `(closure(): int(1))`. [invalid-argument]
phpdoc_advanced_fallback_static_closure.php:45: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure)`, but found `(closure(): int(1))`. [invalid-argument]
phpdoc_advanced_fallback_static_closure.php:48: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure)`, but found `string('strlen')`. [invalid-argument]
Expectation diffLine 24: Expected valid value to be accepted, got ["Invalid return type for function `Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\returnsStaticClosure`: expected `unknown-ref(Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\static-closure)`, but found `(closure(): int(1))`. [invalid-return-statement]"] Line 39: Expected valid value to be accepted, got ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\acceptsClosure`: expected `(closure(...mixed=): mixed)`, but found `unknown-ref(Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\static-closure)`. [invalid-argument]"] Line 42: Expected valid value to be accepted, got ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\acceptsStaticClosure`: expected `unknown-ref(Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\static-closure)`, but found `(closure(): int(1))`. [invalid-argument]"] |
| mir | 0.70.1mir 0.70.1 | Incidental (2/2) | phpdoc_advanced_fallback_static_closure.php:42: InvalidArgument: Argument $value of acceptsStaticClosure() expects 'Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure', got 'Closure(): int' [MIR0201] phpdoc_advanced_fallback_static_closure.php:45: InvalidArgument: Argument $value of acceptsStaticClosure() expects 'Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure', got 'Closure(): int' [MIR0201] phpdoc_advanced_fallback_static_closure.php:48: InvalidArgument: Argument $value of acceptsStaticClosure() expects 'Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure', got '"strlen"' [MIR0201]
Expectation diffLine 42: Expected valid value to be accepted, got ["InvalidArgument: Argument $value of acceptsStaticClosure() expects 'Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\static-closure', got 'Closure(): int' [MIR0201]"] |
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Unrecognized | phpdoc_advanced_fallback_static_closure.php:20: Class 'Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure' not found [unknown_class] phpdoc_advanced_fallback_static_closure.php:32: Class 'Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure' not found [unknown_class]
|
| intelephense | 1.18.5intelephense 1.18.5 | Incidental (0/2) | phpdoc_advanced_fallback_static_closure.php:39: Expected type 'Closure'. Found 'Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure'. [P1006]
Expectation diffLine 39: Expected valid value to be accepted, got ["Expected type 'Closure'. Found 'Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\static-closure'. [P1006]"] |
| phpy | 0.2.0phpy 0.2.0 | Unrecognized | phpdoc_advanced_fallback_static_closure.php:20: Use of unknown class: 'Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure' phpdoc_advanced_fallback_static_closure.php:24: Return value of Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\returnsStaticClosure() is expected to be of type Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure, callable returned phpdoc_advanced_fallback_static_closure.php:32: Use of unknown class: 'Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure' phpdoc_advanced_fallback_static_closure.php:42: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure() is expected to be of type Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure, callable given phpdoc_advanced_fallback_static_closure.php:45: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure() is expected to be of type Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure, callable given phpdoc_advanced_fallback_static_closure.php:48: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure() is expected to be of type Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure, string given
Expectation diffLine 24: Expected valid value to be accepted, got ["Return value of Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\returnsStaticClosure() is expected to be of type Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\static-closure, callable returned"] Line 42: Expected valid value to be accepted, got ["Argument '1' passed to Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\acceptsStaticClosure() is expected to be of type Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\static-closure, callable given"] |
| qodana | 262.8665.325Qodana 262.8665.325 | Unrecognized | phpdoc_advanced_fallback_static_closure.php:20: Return type in PHPDoc does not match the actual return type [PhpReturnDocTypeMismatchInspection] phpdoc_advanced_fallback_static_closure.php:20: Undefined class 'static-closure' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_static_closure.php:24: Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection] phpdoc_advanced_fallback_static_closure.php:32: Undefined class 'static-closure' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_static_closure.php:42: Parameter 'static fn (): int => 1' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_static_closure.php:45: Parameter 'fn (): int => 1' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_static_closure.php:48: Parameter ''strlen'' type is not compatible with declaration [PhpParamsInspection]
Expectation diffLine 24: Expected valid value to be accepted, got ["Return value type is not compatible with declared [PhpIncompatibleReturnTypeInspection]"] Line 42: Expected valid value to be accepted, got ["Parameter 'static fn (): int => 1' type is not compatible with declaration [PhpParamsInspection]"] |
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Unrecognized ⚠ 1 false positive | phpdoc_advanced_fallback_static_closure.php:12: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure does not exist [undefinedClass] phpdoc_advanced_fallback_static_closure.php:32: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure does not exist [undefinedClass]
Expectation diffLine 12: Unexpected errors ["Class or interface named \\Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\static-closure does not exist [undefinedClass]"] |
| steins | 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | Enforced | phpdoc_advanced_fallback_static_closure.php:45: callable argument to acceptsStaticClosure() violates declared @param static-closure $value — the bound closure is not declared static [phpdoc.param-mismatch] phpdoc_advanced_fallback_static_closure.php:48: argument "strlen" to acceptsStaticClosure() violates declared @param static-closure $value — declared contract violation [phpdoc.param-mismatch]
|
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced | phpdoc_advanced_fallback_static_closure.php:45: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure expects static-Closure, Closure(): 1 given. [identifier=argument.type] phpdoc_advanced_fallback_static_closure.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure expects static-Closure, 'strlen' given. [identifier=argument.type]
|
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Unrecognized | phpdoc_advanced_fallback_static_closure.php:22: Unrecognized type Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure in docblock for Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\returnsStaticClosure [InvalidDocblock] phpdoc_advanced_fallback_static_closure.php:22: Method Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\returnsStaticClosure does not have a return type, expecting pure-Closure():1 [MissingReturnType] phpdoc_advanced_fallback_static_closure.php:32: Unrecognized type Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\static-closure in docblock for Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsStaticClosure [InvalidDocblock] phpdoc_advanced_fallback_static_closure.php:34: Parameter $value has no provided type [MissingParamType] phpdoc_advanced_fallback_static_closure.php:39: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackStaticClosure\acceptsClosure cannot be mixed, expecting impure-Closure [MixedArgument]
Expectation diffLine 39: Expected valid value to be accepted, got ["Argument 1 of Conformance\\Tests\\PhpdocAdvancedFallbackStaticClosure\\acceptsClosure cannot be mixed, expecting impure-Closure [MixedArgument]"] |
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedFallbackStaticClosure;
/**
* `static-closure`
*
* A `Closure` declared `static`, which is the one that cannot be bound to an
* object and so can never touch `$this`. Unlike purity this is written in the
* syntax, so an analyzer has no excuse for missing it — the probe is an
* ordinary closure, identical but for the keyword.
*
* References:
* - PHPStan TypeNodeResolver `static-closure` resolves to ClosureType(isStatic: yes)
*/
/**
* @return static-closure
*/
function returnsStaticClosure() // T: static-closure
{
return static fn (): int => 1; // V
}
function acceptsClosure(\Closure $value): void
{
}
/**
* @param static-closure $value
*/
function acceptsStaticClosure($value): void // T: static-closure
{
}
// A `static-closure` value always satisfies a native `Closure` parameter.
acceptsClosure(returnsStaticClosure()); // V
// A static closure satisfies the parameter.
acceptsStaticClosure(static fn (): int => 1); // V
// A closure without the keyword does not.
acceptsStaticClosure(fn (): int => 1); // E?: a non-static closure is not a static-closure
// Nor does a callable that is not a Closure at all.
acceptsStaticClosure('strlen'); // E?: a callable-string is not a Closure