質問

私は、ディスク上のキャッシュを希望するいくつかのオブジェクトを持っています。私は、このプロセスでシリアル化を()を使用します。オブジェクトは他のオブジェクトへのいくつかの参照が含まれています。それはunserializingときに、同じ実世界のオブジェクトのインスタンスを複製、私を与えるので、私は(それはいくつかの他の場所で行われている)ものとしてもシリアル化する必要はありません。

ではない前と(UN後)(文字列へのオブジェクト参照に変更する方法があります(同じオブジェクトを参照するには、しかし、IDによって)シリアライズとバックした後、それらを変更する前に、クラスコード内でこれを行うには)文をシリアル化?

グッドます:

class TheStuff {
 private $otherThing;
 private function __yeahDudeDoThisOnSerialize() {
  $this->otherThing = $this->otherThing->name;
 }
 private function __viceVersa() {
  $this->otherThing = get_thing_by_name($this->otherThing);
 }
}

serialize($someStuff);

悪います:

class TheStuff {
 private $otherThing;
 public function yeahDudeDoThisOnSerialize() {
  $this->otherThing = $this->otherThing->name;
 }
 public function viceVersa() {
  $this->otherThing = get_thing_by_name($this->otherThing);
 }
}

$someStuff->yeahDudeDoThisOnSerialize();
serialize($someStuff);
$someStuff->viceVersa();
役に立ちましたか?

解決

私はあなたが__sleep()および__wakeup()を探していると思います。

http://php.net/manual/en/language.oop5 .magic.phpする

他のヒント

scroll top