相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
PHP中串行化用法示例
本文實例講述了PHP中串行化用法。分享給大家供大家參考,具體如下:
功能:串行化用于對對象的存儲或者傳輸,通過反串行化得到這個對象。
1. Person.class.php:
<?php /* 作者 : shyhero */ class Person{ //聲明一個Person類 public $age; private $name; protected $sex; public function __construct($age="",$name="",$sex=""){ $this -> age = $age; $this -> name = $name; $this -> sex = $sex; } public function say(){ return $this -> age." ".$this -> name." ".$this -> sex; } function __sleep(){ //指定串行化時能提取的成員屬性,沒有參數(shù),但是必須返回一個數(shù)組 $arr = array("age","name"); return $arr; } function __wakeup(){ //指定反串行化時,提取出來的值 $this -> sex = "woman"; } }