open-resourceresource and closed-resource —
so it accepts the word without modelling the distinction the word is for.
The probe is a handle used after fclose(), which separates an analyzer that
tracks the state of a handle from one that only checks it is a resource.
References:
- PHPStan TypeNodeResolver open-resource and closed-resource share one case, both resolving to ResourceType| 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_open_resource.php:21: Saw possibly unextractable annotation for a fragment of comment '* @param open-resource $value': after open, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName] phpdoc_advanced_fallback_open_resource.php:21: Saw a token Phan may have failed to parse after '* @param open-resource $value': after open, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_fallback_open_resource.php:23: Parameter $value has undeclared type \Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open [PhanUndeclaredTypeParameter] phpdoc_advanced_fallback_open_resource.php:31: Argument 1 ($value) is $handle of type resource but \Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource() takes \Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_open_resource.php:23 [PhanTypeMismatchArgument] phpdoc_advanced_fallback_open_resource.php:34: Argument 1 ($value) is 'not a resource' of type string but \Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource() takes \Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_open_resource.php:23 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_open_resource.php:41: Argument 1 ($value) is $closed of type resource but \Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource() takes \Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_open_resource.php:23 [PhanTypeMismatchArgument]
Expectation diffLine 31: Expected valid value to be accepted, got ["Argument 1 ($value) is $handle of type resource but \\Conformance\\Tests\\PhpdocAdvancedFallbackOpenResource\\acceptsOpenResource() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackOpenResource\\open defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_open_resource.php:23 [PhanTypeMismatchArgument]"] |
| phpstan | 2.2.15PHPStan - PHP Static Analysis Tool 2.2.15 | Partly enforced (1/2) reported Lv.5+ | phpdoc_advanced_fallback_open_resource.php:34: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource expects resource, string given. [reported-from-level=5] With strict-rulesphpdoc_advanced_fallback_open_resource.php:34: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource expects resource, string given.
|
| psalm | 6.18.0Psalm 6.18.0@536dd6236b39a5115385b0307b42d6d1ad431a02 next: 7.0.0-beta22 |
Unrecognized (pzoom≠) | phpdoc_advanced_fallback_open_resource.php:21: Unrecognized type open-resource in docblock for Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource [InvalidDocblock] phpdoc_advanced_fallback_open_resource.php:23: Parameter $value has no provided type [MissingParamType] pzoom (Psalm port)phpdoc_advanced_fallback_open_resource.php:34: Argument 1 of acceptsOpenResource expects resource, but 'not a resource' provided [InvalidArgument]
|
| mago | 1.50.0mago 1.50.0 | Partly enforced (1/2) | phpdoc_advanced_fallback_open_resource.php:34: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource`: expected `open-resource`, but found `string('not a resource')`. [invalid-argument]
|
| mir | 0.78.0mir 0.78.0 | Enforced ⚠ 2 false positives | phpdoc_advanced_fallback_open_resource.php:27: MixedAssignment: Variable $handle is assigned a mixed type [MIR1201] phpdoc_advanced_fallback_open_resource.php:31: MixedArgument: Argument $value of acceptsOpenResource() is mixed [MIR1200] phpdoc_advanced_fallback_open_resource.php:34: InvalidArgument: Argument $value of acceptsOpenResource() expects 'Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open-resource', got '"not a resource"' [MIR0201] phpdoc_advanced_fallback_open_resource.php:36: MixedAssignment: Variable $closed is assigned a mixed type [MIR1201] phpdoc_advanced_fallback_open_resource.php:41: MixedArgument: Argument $value of acceptsOpenResource() is mixed [MIR1200]
Expectation diffLine 31: Expected valid value to be accepted, got ["MixedArgument: Argument $value of acceptsOpenResource() is mixed [MIR1200]"] Line 27: Unexpected errors ["MixedAssignment: Variable $handle is assigned a mixed type [MIR1201]"] Line 36: Unexpected errors ["MixedAssignment: Variable $closed is assigned a mixed type [MIR1201]"] |
| phpantom | 0.10.0phpantom_lsp 0.10.0 | Not enforced | No diagnostics reported.
|
| intelephense | 1.18.5intelephense 1.18.5 | Not enforced | No diagnostics reported.
|
| phpactor | 2026.06.23.0Phpactor 2026.06.23.0 | Not enforced | No diagnostics reported.
|
| phpy | 1.0.19274phpy 1.0.19274 | Unrecognized | phpdoc_advanced_fallback_open_resource.php:21: Use of unknown class: 'Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open-resource' phpdoc_advanced_fallback_open_resource.php:31: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource() is expected to be of type Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open-resource, bool|resource given phpdoc_advanced_fallback_open_resource.php:34: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource() is expected to be of type Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open-resource, string given phpdoc_advanced_fallback_open_resource.php:41: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource() is expected to be of type Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open-resource, bool|resource given
Expectation diffLine 31: Expected valid value to be accepted, got ["Argument '1' passed to Conformance\\Tests\\PhpdocAdvancedFallbackOpenResource\\acceptsOpenResource() is expected to be of type Conformance\\Tests\\PhpdocAdvancedFallbackOpenResource\\open-resource, bool|resource given"] |
| qodana | 262.9437.196Qodana 262.9437.196 | Unrecognized | phpdoc_advanced_fallback_open_resource.php:21: Undefined class 'open-resource' [PhpUndefinedClassInspection] phpdoc_advanced_fallback_open_resource.php:31: Parameter '$handle' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_open_resource.php:34: Parameter ''not a resource'' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_open_resource.php:41: Parameter '$closed' type is not compatible with declaration [PhpParamsInspection]
Expectation diffLine 31: Expected valid value to be accepted, got ["Parameter '$handle' 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 | Partly enforced (1/2) ⚠ 2 false positives | phpdoc_advanced_fallback_open_resource.php:12: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open-resource does not exist [undefinedClass] phpdoc_advanced_fallback_open_resource.php:31: potentially not safe call in function Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource signature of param value [notSafeCall] phpdoc_advanced_fallback_open_resource.php:38: potentially not safe call in function fclose signature of param stream [notSafeCall] phpdoc_advanced_fallback_open_resource.php:41: potentially not safe call in function Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource signature of param value [notSafeCall]
Expectation diffLine 31: Expected valid value to be accepted, got ["potentially not safe call in function Conformance\\Tests\\PhpdocAdvancedFallbackOpenResource\\acceptsOpenResource signature of param value [notSafeCall]"] Line 12: Unexpected errors ["Class or interface named \\Conformance\\Tests\\PhpdocAdvancedFallbackOpenResource\\open-resource does not exist [undefinedClass]"] Line 38: Unexpected errors ["potentially not safe call in function fclose signature of param stream [notSafeCall]"] |
| steins | 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) | Enforced | phpdoc_advanced_fallback_open_resource.php:34: argument "not a resource" to acceptsOpenResource() violates declared @param open-resource $value — declared contract violation [phpdoc.param-mismatch] phpdoc_advanced_fallback_open_resource.php:41: argument a closed resource to acceptsOpenResource() violates declared @param open-resource $value — declared contract violation [phpdoc.param-mismatch]
|
| phpstan-strict | 2.2.15PHPStan - PHP Static Analysis Tool 2.2.15 | Partly enforced (1/2) | phpdoc_advanced_fallback_open_resource.php:34: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource expects resource, string given.
|
| psalm-next | 7.0.0-beta22Psalm 7.0.0-beta22@de27e5724ee5997a1e3baee4d394ca6f4e46eba0 | Unrecognized | phpdoc_advanced_fallback_open_resource.php:21: Unrecognized type open-resource in docblock for Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource [InvalidDocblock] phpdoc_advanced_fallback_open_resource.php:23: Parameter $value has no provided type [MissingParamType]
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedFallbackOpenResource;
/**
* `open-resource`
*
* A resource handle that has not been closed. PHPStan resolves the spelling to
* a plain ResourceType — the same type as `resource` and `closed-resource` —
* so it accepts the word without modelling the distinction the word is for.
* The probe is a handle used after `fclose()`, which separates an analyzer that
* tracks the state of a handle from one that only checks it is a resource.
*
* References:
* - PHPStan TypeNodeResolver `open-resource` and `closed-resource` share one case, both resolving to ResourceType
*/
/**
* @param open-resource $value
*/
function acceptsOpenResource($value): void // T: open-resource
{
}
$handle = \fopen('php://memory', 'r');
\assert($handle !== false);
// A freshly opened handle satisfies the parameter.
acceptsOpenResource($handle); // V
// A non-resource does not.
acceptsOpenResource('not a resource'); // E?: a string is not an open-resource
$closed = \fopen('php://memory', 'r');
\assert($closed !== false);
\fclose($closed);
// Still a resource, no longer open.
acceptsOpenResource($closed); // E?: a closed handle is not an open-resource