|
is_resource
Finds whether a variable is a resource
(PHP 4, PHP 5)
Example 2593. is_resource() example<?php Code Examples / Notes » is_resourcetacomage
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. |
Change Languagedebug_zval_dump doubleval empty floatval get_defined_vars get_resource_type gettype import_request_variables intval is_array is_binary is_bool is_buffer is_callable is_double is_float is_int is_integer is_long is_null is_numeric is_object is_real is_resource is_scalar is_string is_unicode isset print_r serialize settype strval unserialize unset var_dump var_export |