resource is not a valid native type declaration| 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 | 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.11PHPStan - PHP Static Analysis Tool 2.2.11 | 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. [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. [reported-from-level=5] native_types_resource_argument.php:38: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesString expects string, resource given. [reported-from-level=5] native_types_resource_argument.php:39: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesInt expects int, resource given. [reported-from-level=5] native_types_resource_argument.php:40: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesBool expects bool, resource given. [reported-from-level=5] With strict-rulesnative_types_resource_argument.php:16: Parameter $value of function Conformance\Tests\NativeTypesResourceArgument\takesResource() has invalid type Conformance\Tests\NativeTypesResourceArgument\resource. native_types_resource_argument.php:37: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesResource expects Conformance\Tests\NativeTypesResourceArgument\resource, resource given. native_types_resource_argument.php:38: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesString expects string, resource given. native_types_resource_argument.php:39: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesInt expects int, resource given. native_types_resource_argument.php:40: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesBool expects bool, resource given. |
| 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.47.4mago 1.47.4 | 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.72.1mir 0.72.1 | Fail | native_types_resource_argument.php:32: MixedAssignment: Variable $handle is assigned a mixed type [MIR1201] native_types_resource_argument.php:38: MixedArgument: Argument $value of takesString() is mixed [MIR1200] native_types_resource_argument.php:39: MixedArgument: Argument $value of takesInt() is mixed [MIR1200] native_types_resource_argument.php:40: MixedArgument: Argument $value of takesBool() is mixed [MIR1200] Expectation diffLine 16: Expected 1 error(s) Line 32: Unexpected errors ["MixedAssignment: Variable $handle is assigned a mixed type [MIR1201]"] |
| phpantom | 0.10.0phpantom_lsp 0.10.0 | Pass | native_types_resource_argument.php:16: Class 'Conformance\Tests\NativeTypesResourceArgument\resource' not found [unknown_class] native_types_resource_argument.php:38: Argument 1 ($value) expects string, got resource [type_mismatch_argument] native_types_resource_argument.php:39: Argument 1 ($value) expects int, got resource [type_mismatch_argument] native_types_resource_argument.php:40: Argument 1 ($value) expects bool, got resource [type_mismatch_argument] |
| 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] |
| phpactor | 2026.07.22.0Phpactor 2026.07.22.0 | Fail | native_types_resource_argument.php:16: Class "resource" not found Expectation diffLine 38: Expected 1 error(s) Line 39: Expected 1 error(s) |
| 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.9437.196Qodana 262.9437.196 | 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 diffLine 16: Expected 1 error(s) |
| steins | 0.1.6steins 0.1.6 (2026-08-25 revision c13b4c7) | Pass | 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] native_types_resource_argument.php:37: argument $handle (holds a resource) to takesResource() cannot become Conformance\Tests\NativeTypesResourceArgument\resource $value — proven TypeError (a resource coerces to nothing, in either mode) [type.argument-mismatch] native_types_resource_argument.php:38: argument $handle (holds a resource) to takesString() cannot become string $value — proven TypeError (a resource coerces to nothing, in either mode) [type.argument-mismatch] native_types_resource_argument.php:39: argument $handle (holds a resource) to takesInt() cannot become int $value — proven TypeError (a resource coerces to nothing, in either mode) [type.argument-mismatch] native_types_resource_argument.php:40: argument $handle (holds a resource) to takesBool() cannot become bool $value — proven TypeError (a resource coerces to nothing, in either mode) [type.argument-mismatch] Notes: Native `resource` is still reported as an undefined class; resource values are now tracked and rejected at string/int/bool call sites. |
| phpstan-strict | 2.2.11PHPStan - PHP Static Analysis Tool 2.2.11 | Pass | native_types_resource_argument.php:16: Parameter $value of function Conformance\Tests\NativeTypesResourceArgument\takesResource() has invalid type Conformance\Tests\NativeTypesResourceArgument\resource. native_types_resource_argument.php:37: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesResource expects Conformance\Tests\NativeTypesResourceArgument\resource, resource given. native_types_resource_argument.php:38: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesString expects string, resource given. native_types_resource_argument.php:39: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesInt expects int, resource given. native_types_resource_argument.php:40: Parameter #1 $value of function Conformance\Tests\NativeTypesResourceArgument\takesBool expects bool, resource given. |
| 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] |
<?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)