note 44467 deleted from function.is-resource by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 06:52:33 +0000 |
| Subject: | note 44467 deleted from function.is-resource by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196684@lists.php.net to get a copy of this message | ||
Note Submitter: tacomage at NOSPAM dot devilishly-deviant dot net
----
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.