← All results

resource is not a valid native type declaration

Group: Native types · Category: language · File: native_types_resource_argument.php

References: - PHP native type declarations - PHP native scalar parameter types - legacy PHP resource values

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 Pass
native_types_resource_argument.php:16: Parameter $value has undeclared type \Conformance\Tests\NativeTypesResourceArgument\resource [PhanUndeclaredTypeParameter]
native_types_resource_argument.php:37: Argument 1 ($value) is $handle of type resource but \Conformance\Tests\NativeTypesResourceArgument\takesResource() takes \Conformance\Tests\NativeTypesResourceArgument\resource defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/native_types_resource_argument.php:16 [PhanTypeMismatchArgument]
native_types_resource_argument.php:38: Argument 1 ($value) is $handle of type resource but \Conformance\Tests\NativeTypesResourceArgument\takesString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/native_types_resource_argument.php:20 [PhanTypeMismatchArgument]
native_types_resource_argument.php:39: Argument 1 ($value) is $handle of type resource but \Conformance\Tests\NativeTypesResourceArgument\takesInt() takes int defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/native_types_resource_argument.php:24 [PhanTypeMismatchArgument]
native_types_resource_argument.php:40: Argument 1 ($value) is $handle of type resource but \Conformance\Tests\NativeTypesResourceArgument\takesBool() takes bool defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/native_types_resource_argument.php:28 [PhanTypeMismatchArgument]
phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Pass reported Lv.0+
native_types_resource_argument.php:16: Parameter $value of function Conformance\Tests\NativeTypesResourceArgument\takesResource() has invalid type Conformance\Tests\NativeTypesResourceArgument\resource. [identifier=class.notFound] [reported-from-level=0]
native_types_resource_argument.php:37: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesResource expects Conformance\Tests\NativeTypesResourceArgument\resource, resource given. [identifier=argument.type] [reported-from-level=5]
native_types_resource_argument.php:38: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesString expects string, resource given. [identifier=argument.type] [reported-from-level=5]
native_types_resource_argument.php:39: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesInt expects int, resource given. [identifier=argument.type] [reported-from-level=5]
native_types_resource_argument.php:40: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesBool expects bool, resource given. [identifier=argument.type] [reported-from-level=5]
With strict-rules
native_types_resource_argument.php:16: Parameter $value of function Conformance\Tests\NativeTypesResourceArgument\takesResource() has invalid type Conformance\Tests\NativeTypesResourceArgument\resource. [identifier=class.notFound]
native_types_resource_argument.php:37: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesResource expects Conformance\Tests\NativeTypesResourceArgument\resource, resource given. [identifier=argument.type]
native_types_resource_argument.php:38: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesString expects string, resource given. [identifier=argument.type]
native_types_resource_argument.php:39: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesInt expects int, resource given. [identifier=argument.type]
native_types_resource_argument.php:40: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesBool expects bool, resource given. [identifier=argument.type]
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Pass
native_types_resource_argument.php:16: Class, interface or enum named Conformance\Tests\NativeTypesResourceArgument\resource does not exist [UndefinedClass]
native_types_resource_argument.php:37: Argument 1 of Conformance\Tests\NativeTypesResourceArgument\takesResource expects Conformance\Tests\NativeTypesResourceArgument\resource, but resource provided [InvalidArgument]
native_types_resource_argument.php:38: Argument 1 of Conformance\Tests\NativeTypesResourceArgument\takesString expects string, but resource provided [InvalidArgument]
native_types_resource_argument.php:39: Argument 1 of Conformance\Tests\NativeTypesResourceArgument\takesInt expects int, but resource provided [InvalidArgument]
native_types_resource_argument.php:40: Argument 1 of Conformance\Tests\NativeTypesResourceArgument\takesBool expects bool, but resource provided [InvalidArgument]
mago 1.46.0mago 1.46.0 Pass
native_types_resource_argument.php:16: Cannot find class, interface, enum, or type alias `Conformance\Tests\NativeTypesResourceArgument\resource`. [non-existent-class-like]
native_types_resource_argument.php:37: Invalid argument type for argument #1 of `Conformance\Tests\NativeTypesResourceArgument\takesResource`: expected `unknown-ref(Conformance\Tests\NativeTypesResourceArgument\resource)`, but found `open-resource`. [invalid-argument]
native_types_resource_argument.php:38: Invalid argument type for argument #1 of `Conformance\Tests\NativeTypesResourceArgument\takesString`: expected `string`, but found `open-resource`. [invalid-argument]
native_types_resource_argument.php:39: Invalid argument type for argument #1 of `Conformance\Tests\NativeTypesResourceArgument\takesInt`: expected `int`, but found `open-resource`. [invalid-argument]
native_types_resource_argument.php:40: Invalid argument type for argument #1 of `Conformance\Tests\NativeTypesResourceArgument\takesBool`: expected `bool`, but found `open-resource`. [invalid-argument]
mir 0.70.1mir 0.70.1 Fail
native_types_resource_argument.php:16: UndefinedClass: Class Conformance\Tests\NativeTypesResourceArgument\resource does not exist [MIR0005]
Expectation diff
Line 38: Expected 1 error(s)
Line 39: Expected 1 error(s)
phpantom 0.9.0phpantom_lsp 0.9.0 Fail
native_types_resource_argument.php:38: Argument 1 ($value) expects string, got resource|false [type_mismatch_argument]
native_types_resource_argument.php:39: Argument 1 ($value) expects int, got resource|false [type_mismatch_argument]
Expectation diff
Line 16: Expected 1 error(s)
intelephense 1.18.5intelephense 1.18.5 Pass
native_types_resource_argument.php:16: Undefined type 'Conformance\Tests\NativeTypesResourceArgument\resource'. [P1009]
native_types_resource_argument.php:37: Expected type 'Conformance\Tests\NativeTypesResourceArgument\resource'. Found 'resource'. [P1006]
native_types_resource_argument.php:38: Expected type 'string'. Found 'resource'. [P1006]
native_types_resource_argument.php:39: Expected type 'int'. Found 'resource'. [P1006]
native_types_resource_argument.php:40: Expected type 'bool'. Found 'resource'. [P1006]
phpy 0.2.0phpy 0.2.0 Pass
native_types_resource_argument.php:16: Use of unknown class: 'Conformance\Tests\NativeTypesResourceArgument\resource'
native_types_resource_argument.php:37: Argument '1' passed to Conformance\Tests\NativeTypesResourceArgument\takesResource() is expected to be of type Conformance\Tests\NativeTypesResourceArgument\resource, bool|resource given
native_types_resource_argument.php:38: Argument '1' passed to Conformance\Tests\NativeTypesResourceArgument\takesString() is expected to be of type string, bool|resource given
native_types_resource_argument.php:39: Argument '1' passed to Conformance\Tests\NativeTypesResourceArgument\takesInt() is expected to be of type int, bool|resource given
qodana 262.8665.325Qodana 262.8665.325 Pass
native_types_resource_argument.php:16: Undefined class 'resource' [PhpUndefinedClassInspection]
native_types_resource_argument.php:37: Parameter '$handle' type is not compatible with declaration [PhpParamsInspection]
native_types_resource_argument.php:38: Parameter '$handle' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
native_types_resource_argument.php:39: Parameter '$handle' type is not compatible with declaration [PhpParamsInspection]
native_types_resource_argument.php:39: Parameter '$handle' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
native_types_resource_argument.php:40: Parameter '$handle' type is not compatible with declaration [PhpParamsInspection]
native_types_resource_argument.php:40: Parameter '$handle' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Fail
native_types_resource_argument.php:37: potentially not safe call in function Conformance\Tests\NativeTypesResourceArgument\takesResource signature of param value [notSafeCall]
native_types_resource_argument.php:38: potentially not safe call in function Conformance\Tests\NativeTypesResourceArgument\takesString signature of param value [notSafeCall]
native_types_resource_argument.php:39: potentially not safe call in function Conformance\Tests\NativeTypesResourceArgument\takesInt signature of param value [notSafeCall]
native_types_resource_argument.php:40: potentially not safe call in function Conformance\Tests\NativeTypesResourceArgument\takesBool signature of param value [notSafeCall]
Expectation diff
Line 16: Expected 1 error(s)
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Fail
native_types_resource_argument.php:16: reference to undefined class Conformance\Tests\NativeTypesResourceArgument\resource — not defined in the project, not on PHP 8.5.9 (70 extensions) [class.undefined]
Expectation diff
Line 38: Expected 1 error(s)
Line 39: Expected 1 error(s)

Notes: Honest deferral, not a refusal: no resource type nor resource-value tracking exists yet (Steins divergence registry, conformance entry 4 — the non-scalar value-modeling cluster).

phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Pass
native_types_resource_argument.php:16: Parameter $value of function Conformance\Tests\NativeTypesResourceArgument\takesResource() has invalid type Conformance\Tests\NativeTypesResourceArgument\resource. [identifier=class.notFound]
native_types_resource_argument.php:37: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesResource expects Conformance\Tests\NativeTypesResourceArgument\resource, resource given. [identifier=argument.type]
native_types_resource_argument.php:38: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesString expects string, resource given. [identifier=argument.type]
native_types_resource_argument.php:39: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesInt expects int, resource given. [identifier=argument.type]
native_types_resource_argument.php:40: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesBool expects bool, resource given. [identifier=argument.type]
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Pass
native_types_resource_argument.php:16: Class, interface or enum named Conformance\Tests\NativeTypesResourceArgument\resource does not exist [UndefinedClass]
native_types_resource_argument.php:37: Argument 1 of Conformance\Tests\NativeTypesResourceArgument\takesResource expects Conformance\Tests\NativeTypesResourceArgument\resource, but resource provided [InvalidArgument]
native_types_resource_argument.php:38: Argument 1 of Conformance\Tests\NativeTypesResourceArgument\takesString expects string, but resource provided [InvalidArgument]
native_types_resource_argument.php:39: Argument 1 of Conformance\Tests\NativeTypesResourceArgument\takesInt expects int, but resource provided [InvalidArgument]
native_types_resource_argument.php:40: Argument 1 of Conformance\Tests\NativeTypesResourceArgument\takesBool expects bool, but resource provided [InvalidArgument]

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\NativeTypesResourceArgument;

/**
 * `resource` is not a valid native type declaration.
 *
 * References:
 * - PHP native type declarations
 * - PHP native scalar parameter types
 * - legacy PHP resource values
 */

function takesResource(resource $value): void // E: resource is not a supported native parameter type
{
}

function takesString(string $value): void
{
}

function takesInt(int $value): void
{
}

function takesBool(bool $value): void
{
}

$handle = fopen('php://memory', 'r');
if ($handle === false) {
    throw new \RuntimeException('failed to open memory stream');
}

takesResource($handle); // E?: resource-typed parameters should also be rejected at call sites
takesString($handle); // E: resource is not accepted by string parameter
takesInt($handle); // E: resource is not accepted by int parameter
takesBool($handle); // E?: resource is not accepted by bool parameter (bool is the one scalar most tools model as universally accepting)