序列化和反序列化函数

时间:2016-10-25 14:15:28

标签: php serialization

我知道序列化是一个采用复杂对象并将其减少为零和存储或传输的过程。但我对Serializable接口感到困惑 例如,我们有像

这样的colde
class Artist implements Serializable {

 public function serialize() {
 return serialize(
 array("earliest" =>self::$earliestDate,
 "first" => $this->firstName,
 "last" => $this->lastName,
 "bdate" => $this->birthDate,
 "ddate" => $this->deathDate,
 "bcity" => $this->birthCity,
 "works" => $this->artworks
 );
 );
 }
 public function unserialize($data) {
 $data = unserialize($data);
 self::$earliestDate = $data['earliest'];
 $this->firstName = $data['first'];
 $this->lastName = $data['last'];
 $this->birthDate = $data['bdate'];
 $this->deathDate = $data['ddate'];
 $this->birthCity = $data['bcity'];
 $this->artworks = $data['works'];
 }
 //...
}

例如,unserialize($ data)是我们实现的方法,但是它如何在函数内调用自己,如“$ data = unserialize($ data)”,这不是一个无限循环吗?内部函数是否反序列化($ data)与外部unserialize($ data)函数相同?

0 个答案:

没有答案