Problem serializing an object tree with SplObjectStorage

Kemgroume

New Member
I have implemented a simple Composite pattern using SplObjectStorage, like the example above:\[code\]class Node{ private $parent = null; public function setParent(Composite $parent) { $this->parent = $parent; }}class Composite extends Node{ private $children; public function __construct() { $this->children = new SplObjectStorage; } public function add(Node $node) { $this->children->attach($node); $node->setParent($this); }}\[/code\]Whenever I try to serialize a Composite object, PHP 5.3.2 throws me a \[code\]Segmentation Fault\[/code\].This only happens when I add any number of nodes of any type to the object.This is the offending code:\[code\]$node = new Node;$composite = new Composite;$composite->add($node);echo serialize($composite);\[/code\]Although this one works:\[code\]$node = new Node;$composite = new Composite;echo serialize($composite);\[/code\]Also, if I implement the Composite pattern with array() instead of SplObjectStorage, all runs ok too.What I'm making wrong?
 
Back
Top