Sleep and wakeup example (bug #34397)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@196444 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Jakub Vrana 2005-09-20 12:50:10 +00:00
parent 83c7ec65fd
commit 982b0ff3f6

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- $Revision: 1.11 $ -->
<sect1 id="language.oop5.magic">
<title>Magic Methods</title>
<para>
@ -60,6 +60,44 @@
during serialization and perform other reinitialization
tasks.
</para>
<example>
<title>Sleep and wakeup</title>
<programlisting role="php">
<![CDATA[
<?php
class Connection {
protected $link;
private $server, $username, $password, $db;
public function __construct($server, $username, $password, $db)
{
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->db = $db;
$this->connect();
}
private function connect()
{
$this->link = mysql_connect($this->server, $this->username, $this->password);
mysql_select_db($this->db, $this->link);
}
public function __sleep()
{
mysql_close($this->link);
}
public function __wakeup()
{
$this->connect();
}
}
?>
]]>
</programlisting>
</example>
</sect2>
<sect2 id="language.oop5.magic.tostring">