什么是"* RECURSION *"在print_r中输出是什么意思?

什么是

问题描述:

我正在使用此递归代码读取另一个目录中的所有目录,并将它们存储在父目录中.

I'm using this recursive code to read all directories inside another directory, and store them within the parent directory.

protected function readDirs($parent)
    {       
        $currentDir = $parent->source();
        $items = scandir($currentDir);

        foreach ($items as $itemName)
        {
            if (Dir::isIgnorable($itemName) )
                continue;

            $itemPath = $currentDir.SLASH.$itemName;
            if (! is_dir($itemPath) )
                continue;

            $item = new ChangeItem(TYPE_DIR);            
            $item->parent($parent)->source($itemPath);

            $parent->children[ $itemName ] = $item;

            $this->readDirs($item);
        }
    }

完成此操作后,如果我在存储其他所有内容的全局对象上执行print_r(),对于某些项目,它说:

After this is done, if I do a print_r() on the global Object which is storing everything else, for some of the items it says:

[parent:protected] => ChangeItem Object
 *RECURSION*

那是什么意思?我能否访问父对象?

What does that mean? Will I be able to access the parent object or not?

这意味着该属性是对print_r已经访问过的对象的引用. print_r会检测到此情况,并且不会继续沿该路径前进;否则,结果输出将无限长.

It means that the property is a reference to an object that has already been visited by print_r. print_r detects this and doesn't continue down that path; otherwise, the resulting output would be infinitely long.

在程序的上下文中,由于scandir还返回对当前目录和父目录(分别命名为...)的引用,跟随它们将导致递归.跟随符号链接也可能导致递归.

In the context of your program, as scandir also returns references to the current and parent directories (named . and .., respectively), following them would lead to recursion. Following symbolic links may also cause recursion.