Suggestion: here's a "recursive traverser" and "next/prev attributes" that some might find useful ...
I developed a very simple "recursive traverser" in order to build a program that, upon encountering an include() or require() directive, could immediately traverse into what it contained. It simply modifies the regular traverser so that, if leaveNode returns an array, that array is immediately traversed.
Later on, I found that I had the need to support next and prev attributes to let me walk the completed tree – without using actual references so that print_r() wouldn't recurse itself to death. This I did by placing the references in a separate array and storing the indexes to that array as the values of the attributes.
I'd like to suggest that these simple alternatives ought to become "official." When them, I was able to build many important tools – an undefined-variables finder, a "register globals" replacement calculator, and so on. Note that they do presume that the tree structure being walked is not being changed by the walker – which your "official" walkers, of course, specifically provide for.
(The attached file was last modified in July, 2017 and won't reflect any changes you've made to the underlying classes since then.)
Why not send a PR with the code? It would be much easier to review and feedback on
I guess this one can be closed after 4 years.
There already are visitors for adding parent/next/prev attributes (ParentConnectingVisitor, NodeConnectingVisitor). Traversal past include/require is something I would consider out of scope for this project, because it requires filesystem resolution, and has limited relevance nowadays (in the age of autoloading).