Unserializes, inheritance and allows_classes
| From: | Marcos Passos | Date: | Thu, 17 Jan 2019 23:48:51 +0000 |
| Subject: | Unserializes, inheritance and allows_classes | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-103756@lists.php.net to get a copy of this message | ||
Hi internals,
Today I stumbled upon a limitation when implementing the unserialize method
of a serializable class which depends on an abstraction also serializable.
Currently, there is no way to unserialize an object specifying a parent
class in the allowed_classes option:
class SerializableBase implements \Serializable {
> }
> class SerializableChild extends SerializableBase {
> }
> class Foo implements \Serializable {
> private $dependency;
> public function __construct(SerializableBase $dependency) {
> $this->dependency = $dependency;
> }
> public function serialize() : string {
> return \serialize($this->dependency);
> }
> public function unserialize($data) : void {
> $this->dependency = \unserialize($data, ['allowed_classes' =>
> SerializableBase::class]);
> }
> }
Is this an intentional limitation?
- Marcos