Skip to main content
Post Closed as "Duplicate" by miken32 php
added 7 characters in body
Source Link
NueFox
  • 351
  • 1
  • 4
  • 14

Not sure what the process is for serializing a child class that is implementing the Serializable interface, the parent class no longer retains the data it was once serializing. Is there a step I am missing?

class A { private $aVar = "test"; } class B extends A implements Serializable { private static $bVar = "tset"; public function serialize() { return serialize($this->bVarself::$bVar); } public function unserialize($serialized) { $this->bVarself::$bVar = unserialize($serialized); } } $s = serialize(new B()); $u = unserialize($s); 

Not sure what the process is for serializing a child class that is implementing the Serializable interface, the parent class no longer retains the data it was once serializing. Is there a step I am missing?

class A { private $aVar = "test"; } class B extends A implements Serializable { private $bVar = "tset"; public function serialize() { return serialize($this->bVar); } public function unserialize($serialized) { $this->bVar = unserialize($serialized); } } $s = serialize(new B()); $u = unserialize($s); 

Not sure what the process is for serializing a child class that is implementing the Serializable interface, the parent class no longer retains the data it was once serializing. Is there a step I am missing?

class A { private $aVar = "test"; } class B extends A implements Serializable { private static $bVar = "tset"; public function serialize() { return serialize(self::$bVar); } public function unserialize($serialized) { self::$bVar = unserialize($serialized); } } $s = serialize(new B()); $u = unserialize($s); 
Source Link
NueFox
  • 351
  • 1
  • 4
  • 14

PHP Serialization and Inheritance

Not sure what the process is for serializing a child class that is implementing the Serializable interface, the parent class no longer retains the data it was once serializing. Is there a step I am missing?

class A { private $aVar = "test"; } class B extends A implements Serializable { private $bVar = "tset"; public function serialize() { return serialize($this->bVar); } public function unserialize($serialized) { $this->bVar = unserialize($serialized); } } $s = serialize(new B()); $u = unserialize($s);