resourceresource in a signature, so the PHPDoc form is the only way to say
it and there is no base type to fall back to. Analyzers that model it reject
a non-handle; others treat the word as a class name or as mixed.
References:
- PHPStan TypeNodeResolver resource resolves to ResourceType, after trying a pseudo-type class| 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 | Enforced | phpdoc_advanced_fallback_resource.php:33: Argument 1 ($value) is 123 of type int (value: 123) but \Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource() takes resource (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_resource.php:22 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_resource.php:34: Argument 1 ($value) is 'php://memory' of type string but \Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource() takes resource (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_resource.php:22 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal] phpdoc_advanced_fallback_resource.php:35: Argument 1 ($value) is new \stdClass() of type \stdClass but \Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource() takes resource (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_resource.php:22 (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_resource.php:33: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, int given. [identifier=argument.type] [reported-from-level=5] phpdoc_advanced_fallback_resource.php:34: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, string given. [identifier=argument.type] [reported-from-level=5] phpdoc_advanced_fallback_resource.php:35: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, stdClass given. [identifier=argument.type] [reported-from-level=5] With strict-rulesphpdoc_advanced_fallback_resource.php:33: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, int given. [identifier=argument.type] phpdoc_advanced_fallback_resource.php:34: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, string given. [identifier=argument.type] phpdoc_advanced_fallback_resource.php:35: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, stdClass given. [identifier=argument.type]
|
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Enforced | phpdoc_advanced_fallback_resource.php:33: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, but 123 provided [InvalidArgument] phpdoc_advanced_fallback_resource.php:34: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, but 'php://memory' provided [InvalidArgument] phpdoc_advanced_fallback_resource.php:35: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, but stdClass provided [InvalidArgument]
|
| mago | 1.46.0mago 1.46.0 | Enforced | phpdoc_advanced_fallback_resource.php:33: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource`: expected `resource`, but found `int(123)`. [invalid-argument]
phpdoc_advanced_fallback_resource.php:34: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource`: expected `resource`, but found `string('php://memory')`. [invalid-argument]
phpdoc_advanced_fallback_resource.php:35: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource`: expected `resource`, but found `stdClass`. [invalid-argument]
|
| mir | 0.70.1mir 0.70.1 | Not enforced | No diagnostics reported.
|
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Enforced | phpdoc_advanced_fallback_resource.php:33: Argument 1 ($value) expects resource, got 123 [type_mismatch_argument] phpdoc_advanced_fallback_resource.php:34: Argument 1 ($value) expects resource, got 'php://memory' [type_mismatch_argument] phpdoc_advanced_fallback_resource.php:35: Argument 1 ($value) expects resource, got stdClass [type_mismatch_argument]
|
| intelephense | 1.18.5intelephense 1.18.5 | Not enforced | No diagnostics reported.
|
| phpy | 0.2.0phpy 0.2.0 | Enforced | phpdoc_advanced_fallback_resource.php:33: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource() is expected to be of type resource, int given phpdoc_advanced_fallback_resource.php:34: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource() is expected to be of type resource, string given phpdoc_advanced_fallback_resource.php:35: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource() is expected to be of type resource, stdClass given
|
| qodana | 262.8665.325Qodana 262.8665.325 | Enforced | phpdoc_advanced_fallback_resource.php:33: Parameter '123' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_resource.php:34: Parameter ''php://memory'' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_fallback_resource.php:35: Parameter 'new \stdClass()' 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 | Not enforced | phpdoc_advanced_fallback_resource.php:30: potentially not safe call in function Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource signature of param value [notSafeCall]
Expectation diffLine 30: Expected valid value to be accepted, got ["potentially not safe call in function Conformance\\Tests\\PhpdocAdvancedFallbackResource\\acceptsResource signature of param value [notSafeCall]"] |
| steins | 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | Widened to a nonexistent-class reference | No diagnostics reported.
Notes: `resource` is not a native type and has no `lower_identifier` entry, so it lowers to `ContractTy::Class("resource")` and is treated as a reference to a non-existent class (divergence-registry.md entry 4) — no resource-value modeling exists to check against. |
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Enforced | phpdoc_advanced_fallback_resource.php:33: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, int given. [identifier=argument.type] phpdoc_advanced_fallback_resource.php:34: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, string given. [identifier=argument.type] phpdoc_advanced_fallback_resource.php:35: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, stdClass given. [identifier=argument.type]
|
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Enforced | phpdoc_advanced_fallback_resource.php:33: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, but 123 provided [InvalidArgument] phpdoc_advanced_fallback_resource.php:34: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, but 'php://memory' provided [InvalidArgument] phpdoc_advanced_fallback_resource.php:35: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackResource\acceptsResource expects resource, but stdClass provided [InvalidArgument]
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedFallbackResource;
/**
* `resource`
*
* The one type in this group with no native spelling at all: PHP has never
* allowed `resource` in a signature, so the PHPDoc form is the only way to say
* it and there is no base type to fall back to. Analyzers that model it reject
* a non-handle; others treat the word as a class name or as `mixed`.
*
* References:
* - PHPStan TypeNodeResolver `resource` resolves to ResourceType, after trying a pseudo-type class
*/
/**
* @param resource $value
*/
function acceptsResource($value): void // T: resource
{
}
$handle = \fopen('php://memory', 'r');
\assert($handle !== false);
// A stream handle satisfies the parameter.
acceptsResource($handle); // V
// Scalars and objects do not.
acceptsResource(123); // E?: an int is not a resource
acceptsResource('php://memory'); // E?: a string is not a resource
acceptsResource(new \stdClass()); // E?: an object is not a resource