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

search for in the

is_scalar> <is_real
Last updated: Fri, 24 Jul 2009

view this page in

is_resource

(PHP 4, PHP 5)

is_resource 변수가 자원인지 확인

설명

bool is_resource ( mixed $var )

주어진 변수가 자원인지 확인합니다.

인수

var

평가할 변수.

반환값

varresource이면 TRUE, 아니면 FALSE를 반환합니다.

예제

Example #1 is_resource() 예제

<?php

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

?>

참고



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> <is_real
Last updated: Fri, 24 Jul 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites