Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

public function __sleep() and __wakeup()

class demoSleepWakeup {
    public $resourceM;
    public $arrayM;

    public function __construct() {
        $this->resourceM = fopen("demo.txt", "w");
        $this->arrayM = array(1, 2, 3, 4); // Enter code here
    }

    public function __sleep() {
        return array('arrayM');
    }

    public function __wakeup() {
        $this->resourceM = fopen("demo.txt", "w");
    }
}

$obj = new demoSleepWakeup();
$serializedStr = serialize($obj);
var_dump($obj);
var_dump($serializedStr);
var_dump(unserialize($serializedStr));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #public #function
ADD COMMENT
Topic
Name
9+1 =