note 97323 deleted from function.is-resource by danbrown
| From: | danbrown@php.net | Date: | Wed, 14 Apr 2010 17:01:15 +0000 |
| Subject: | note 97323 deleted from function.is-resource by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168236@lists.php.net to get a copy of this message | ||
Note Submitter: pL at fusi0n dot org
----
A better example would be:
<?php
class Example {
protected $db;
function __construct() {
$this->db = mysql_connect('host', 'user', 'pass') or
die(mysql_error());
}
function __destruct() {
if (is_resource($this->db)) { mysql_close($this->db); }
}
}
?>
Use this avoid using error supression on mysql_close() (@mysql_close()) seeing as mysql_close()
throws an E_WARNING when trying to close a resource link that has already been closed.