<?
error_reporting(-1);
class test {
        function test($filename=NULL,$mode=NULL) {
                echo "------------------constructor called\n";
                $this->filename = $filename;
                $this->mode = $mode;

                // we could call $this->_wakeup() instead!
                if ($this->filename && $this->mode) {
                        $this->fd = fopen($this->filename,$this->mode);
                }

        }

        function __sleep() {
                echo "------------------sleep\n";
                // return list of instance-variables to be serialized
                return array("filename","mode");
        }

        function __wakeup() {
                echo "------------------wakeup\n";
                // all serialized instance variables are set now, inititalize the non-serializeable ones
                if ($this->filename && $this->mode) {
                        $this->fd = fopen($this->filename,$this->mode);
                }
        }

        function __string_value() {
                return "hallo i'm using $this->filename\n";
        }
}

$a = new test("/tmp/thies.tcsh","r");
echo $a;
var_dump($a);
$b = serialize($a);
var_dump($b);
$a = unserialize($b);
var_dump($a);

$b = wddx_serialize_value($a);
var_dump($b);
$a = wddx_deserialize($b);
var_dump($a);
?>
