Skip to content

MIR0236

NativeResourceType

PHP has no native resource type. In a signature, resource is read as a class name in the current namespace, so passing an actual resource handle throws TypeError: f(): Argument #1 ($value) must be of type resource, resource given. Only a PHPDoc resource describes a resource handle.

<?php
function close(resource $handle): void {
fclose($handle);
}

Move the type to the docblock:

<?php
/** @param resource $handle */
function close($handle): void {
fclose($handle);
}