PHP: is_resource - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

is_scalar is_real

Last updated: Sat, 27 Jan 2007

view this page in

# is_resource

(PHP 4, PHP 5)

is_resource -- Finds whether a variable is a resource

## Описание

bool is_resource ( mixed var )

Finds whether the given variable is a resource.

## Список параметров

`var`

  The variable being evaluated.

## Возвращаемые значения

Returns `TRUE` if `var` is a resource, `FALSE` otherwise.

## Примеры

Пример 1. is_resource() example

`<?php
$db_link = @mysql_connect('localhost', 'mysql_user', 'mysql_pass');
if (!is_resource($db_link)) {
die('Can\'t connect : ' . mysql_error());
}
?>`

## Смотрите также

The resource-type documentation
get_resource_type()

add a note User Contributed Notes
is_resource
tacomage at NOSPAM dot devilishly-deviant dot net
06-Aug-2004 06:10
`Note that the use of is_resource isn't necessary in the example. mysql_connect (along with any other function that would return a resouce, I imagine) returns false on failure, so the same results could be obtained with:
<?php
$db_link = @mysql_connect('localhost', 'mysql_user', 'mysql_pass');
if (!$db_link) {
die('Can\'t connect : ' . mysql_error());
}
?>
Or even:
<?php
$db_link = @mysql_connect('localhost', 'mysql_user', 'mysql_pass')
or die('Can\'t connect : ' . mysql_error());
}
?>
You'd be more likely to use is_resource AFTER the initial conection, to make sure the variable you intend to use as a resource is, in fact, a connection resource. You might also use is_resource as a sanity-check prior to serializing an object, since resource variables can't be serialized.`
add a note
is_scalar is_real

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST