note 82177 deleted from language.oop5 by googleguy
| From: | googleguy@php.net | Date: | Sat, 12 Jan 2013 09:26:31 +0000 |
| Subject: | note 82177 deleted from language.oop5 by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192953@lists.php.net to get a copy of this message | ||
Note Submitter: ranema at ubuntu dot polarhome dot com
----
Sometimes you just forget to close handles, links, etc and sometimes you are just lazy to do that.
PHP 5 OOP can do it automatically by using destructors:
<?php
class MySqlDriver {
private $_Link;
public function __construct( <...> ) {
$this->_Link = mysql_connect( <...> );
}
// this will be called automatically at the end of scope
public function __destruct() {
mysql_close( $this->_Link );
}
}
$_gLink = new MySqlDriver( <...> );
// and you don't need to close the link manually
?>