我使用SplObjectStorage实现了一个简单的Composite模式,就像上面的例子一样:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
每当我尝试序列化一个Composite对象时,PHP 5.3.2就会抛出一个Segmentation Fault
.只有在向对象添加任意类型的任意数量的节点时才会发生这种情况.
这是违规的代码:
$node = new Node;
$composite = new Composite;
$composite->add($node);
echo serialize($composite);
Run Code Online (Sandbox Code Playgroud)
虽然这个有效:
$node = new Node;
$composite = new Composite;
echo serialize($composite);
Run Code Online (Sandbox Code Playgroud)
另外,如果我使用array()而不是SplObjectStorage实现Composite模式,那么所有运行也都可以.
我做错了什么?
我使用Doctrine2以下管理我的模型:有一个抽象的概念Content
,在一个复合模式Gallery
,也是一个抽象的概念,Media
从Video
和Image
继承.
我的选择是添加鉴别器Content
和Media
表格以区分Gallery
,Video
和Image
.Content
用途JOIN inheritance
和Media
用途SINGLE_TABLE inheritance
.
当我运行时doctrine orm:schema-tool:create --dump-sql
,Media
表正在复制列中的列Content
.这是命令的输出:
CREATE TABLE Content (id INT AUTO_INCREMENT NOT NULL, container_id INT DEFAULT NULL, creationDate DATETIME NOT NULL, publicationDate DATETIME DEFAULT NULL, isGallery TINYINT(1) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE Media (id INT AUTO_INCREMENT NOT NULL, creationDate DATETIME …
Run Code Online (Sandbox Code Playgroud)