What does “ *RECURSION* ” in print_r output mean?

前端 未结 2 1442
日久生厌
日久生厌 2021-02-19 15:10

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

protected function readDirs($parent)         


        
相关标签:
2条回答
  • 2021-02-19 15:14

    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.

    0 讨论(0)
  • 2021-02-19 15:17

    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.

    0 讨论(0)
提交回复
热议问题