← All results

open-resource

Group: Advanced PHPDoc types · Category: ecosystem · File: phpdoc_advanced_fallback_open_resource.php

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

Analyzer results

AnalyzerVersionResultDiagnostics
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]
  • Recognition: spelling not resolved — reported on declaration line(s) 21, 23
  • Enforcement: 2/2 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 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.8PHPStan - PHP Static Analysis Tool 2.2.8 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. [identifier=argument.type] [reported-from-level=5]
With strict-rules
phpdoc_advanced_fallback_open_resource.php:34: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource expects resource, string given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
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]
  • Recognition: spelling not resolved — reported on declaration line(s) 21, 23
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
mago 1.46.0mago 1.46.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]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported
mir 0.70.1mir 0.70.1 Partly enforced (1/2)
phpdoc_advanced_fallback_open_resource.php:34: InvalidArgument: Argument $value of acceptsOpenResource() expects 'Conformance\Tests\PhpdocAdvancedFallbackOpenResource\open-resource', got '"not a resource"' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported
phpantom 0.9.0phpantom_lsp 0.9.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
intelephense 1.18.5intelephense 1.18.5 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
phpy 0.2.0phpy 0.2.0 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
  • Recognition: spelling not resolved — reported on declaration line(s) 21
  • Enforcement: 2/2 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 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.8665.325Qodana 262.8665.325 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]
  • Recognition: spelling not resolved — reported on declaration line(s) 21
  • Enforcement: 2/2 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 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]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported
  • False positives: line(s) 12, 38
Expectation diff
Line 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.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Widened to a nonexistent-class reference

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported

Notes: `open-resource` lowers to `ContractTy::Class("open-resource")` (no `lower_identifier` entry), the same non-existent-class treatment as `resource` (divergence-registry.md entry 4) — open/closed handle state is not modeled.

phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Partly enforced (1/2)
phpdoc_advanced_fallback_open_resource.php:34: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackOpenResource\acceptsOpenResource expects resource, string given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 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]
  • Recognition: spelling not resolved — reported on declaration line(s) 21, 23
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved

Source

<?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