1

所以我有一个看起来大致像这样的 PHP 堆栈

Class Stack {

    public $name;
    public $parent;
    public $children = array();

    public function __construct($name, $parent = false) {
        $this->name = $name;
        $this->parent = $parent;
    }

    public function newChild($name) {
        $this->children[] = new Stack($name, $this);
    }

    public function &top() {
        if(is_object($this->parent))
            return $this->parent->top();
        return $this;
    }

}

所以在这个堆栈的第 5 级附近的某个地方,我想使用 top() 方法访问第 0 级,因为我需要对其进行修改。所以我做了,但我所做的修改不适用于最终的构建序列,因为它是通过引用传递的。我尝试了几个不同的想法,但我仍然无法让它正确通过。有任何想法吗?

编辑:我实际上想通了。我上面写的实际上完美地工作了我正在使用的堆栈有点大,并且在父wasent设置的某个地方,所以它并没有一路上升。看看这实际上是什么项目。看看http://github.com/EvolutionSDK/lhtml(逻辑 HTML ......允许从基于 HTML 的页面对 PHP 的有限访问。基本上 MVC 架构框架中的 C 和 V。)

4

1 回答 1

0

基本上在我的大型 PHP 堆栈中,我有一个未设置的“父”变量。这使 top() 函数无法访问堆栈的顶部。所以它只上升了一部分。

当我弄清楚这一点并将孩子重新连接到其父母时,它工作得很好。因为类总是通过引用传递。

很抱歉我花了多长时间才发布这个。

于 2012-05-15T20:06:35.707 回答