is_resource

Finds whether a variable is a resource

Syntax

is_resource(mixed $value): bool

Parameters

value

The variable being evaluated.

Return

Returns true if value is a resource, false otherwise.

Examples

1 · value

<?

$value = tmpfile();

$return = is_resource($value);

var_dump($value, $return);

?>
resource(2) of type (stream)
bool(true)

2 · open

<?

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/file.txt';
$mode = 'r';

$value = fopen($filename, $mode);

    $return = is_resource($value);

    var_dump($value, $return);

fclose($value);

?>
resource(3) of type (stream)
bool(true)

3 · closed

<?

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/file.txt';
$mode = 'r';

$value = fopen($filename, $mode);
fclose($value);

$return = is_resource($value);

var_dump($value, $return);

?>
resource(3) of type (Unknown)
bool(false)

boolval

debug_zval_dump

doubleval

empty

floatval

get_debug_type

get_defined_vars

get_resource_id

get_resource_type

gettype

intval

is_array

is_bool

is_callable

is_countable

is_double

is_float

is_int

is_integer

is_iterable

is_long

is_null

is_numeric

is_object

is_real

is_scalar

is_string

isset

print_r

serialize

settype

strval

unserialize

unset

var_dump

var_export

PHP

Home Menu