Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

is_resource()

Test whether an extension handle is currently an open resource.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

is_resource(mixed $value): bool

Test whether an extension handle is currently an open resource. Closing a stream makes the predicate false for the same variable. Some extensions expose object handles instead, so choose the check that matches the documented API.

Signature

is_resource(mixed $value): bool

Example output

[true,false,false]

Examples

<?php
$stream = fopen("php://memory", "r");
$open = is_resource($stream);
fclose($stream);
echo json_encode([$open, is_resource($stream), is_resource(new stdClass())]);

Result

[true,false,false]

Sources