是什么意思? *递归*” print_r 输出是什么意思?
我使用此递归代码来读取另一个目录中的所有目录,并将它们存储在父目录中。
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()
,对于某些项目,它会说:
[parent:protected] => ChangeItem Object
*RECURSION*
这是什么意思?我是否能够访问父对象?
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);
}
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这意味着该属性是对已被
print_r
访问过的对象的引用。print_r
检测到这一点并且不会继续沿该路径前进;否则,结果输出将是无限长的。在程序的上下文中,
scandir
还会返回对当前目录和父目录的引用(分别名为.
和..
),如下它们会导致递归。遵循符号链接也可能导致递归。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.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.scandir
返回.
条目,它代表当前目录。然后,您将该目录存储在其父目录(本身)中。于是,递归。我建议忽略
.
和..
。您收到的“RECURSION”消息意味着数据结构无法完整打印,因为它是无限的。
scandir
returns the.
entry, which represents the current directory. You then go to store this directory inside its parent (itself). Thus, recursion.I suggest ignoring
.
and..
.The "RECURSION" message you got means the data structure cannot be printed in its entirety because it would be infinite.