Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: is_resource - Manual
[go: Go Back, main page]

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

search for in the

is_scalar" width="11" height="7"/> <is_real
Last updated: Thu, 31 May 2007

view this page in

is_resource

(PHP 4, PHP 5)

is_resource — 変数がリソースかどうかを調べる

説明

bool is_resource ( mixed $var )

指定した変数がリソースかどうかを調べます。

パラメータ

var

評価する変数。

返り値

varresource の場合に TRUE、 それ以外の場合に FALSE を返します。

例 2519. is_resource() の例

<?php

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

?>

参考

リソース型のドキュメント
get_resource_type()



add a note add a note User Contributed Notes
is_resource
tacomage at NOSPAM dot devilishly-deviant dot net
07-Aug-2004 10: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.

is_scalar" width="11" height="7"/> <is_real
Last updated: Thu, 31 May 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites