Home Menu

is_resource

Finds whether a variable is a resource

Syntax

is_resource ( mixed $var ) : bool

Parameters

var

The variable being evaluated.

Return

Returns TRUE if var is a resource, FALSE otherwise.

Examples

1

<?

$var = tmpfile();

$return = is_resource($var);

var_dump($var, $return);

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

2

<?

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

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

    $return = is_resource($var);
  
    var_dump($var, $return);

fclose($var);

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

3

<?

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

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

$return = is_resource($var);

var_dump($var, $return);

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

PHP

JesusBible
HTMLCSSJSPHPSVGMore
AboutTerms