小编xPh*_*eRe的帖子

使用SplObjectStorage序列化对象树时出错

我使用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模式,那么所有运行也都可以.

我做错了什么?

php spl serialization composite segmentation-fault

5
推荐指数
1
解决办法
1056
查看次数

使用Doctrine2时存在多种歧视级别

我使用Doctrine2以下管理我的模型:有一个抽象的概念Content,在一个复合模式Gallery,也是一个抽象的概念,MediaVideoImage继承.

我的选择是添加鉴别器ContentMedia表格以区分Gallery,VideoImage.Content用途JOIN inheritanceMedia用途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)

php design-patterns doctrine-orm

5
推荐指数
1
解决办法
2368
查看次数