Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code samples in the tree iterator section (p136 on) #10

Open
mattparker opened this issue Apr 15, 2014 · 2 comments
Open

Code samples in the tree iterator section (p136 on) #10

mattparker opened this issue Apr 15, 2014 · 2 comments

Comments

@mattparker
Copy link

Minor typo: code sample p136 has TreeNOde instead of TreeNode

In the samples that follow (p 138, 139) you have a variable name $it and $rii for the TreeIterator and RecursiveIteratorIterator. They're a bit short for some, but it's a bit confusing because the next section talks about the "it" node - which isn't $it. So by the bottom of page 139 you're recursively iterating $it looking for "it" which is an instance of ItTreeNode... In short, some more expressive variable names here would really help clarify the example, I think!

@mattparker
Copy link
Author

Maybe I'll be more constructive: how about something along these lines:

$theTree = new TreeIterator($rootNode);

$treeIterator = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);

foreach ($treeIterator as $treeNode) {
    if ($treeNode instanceof ItTreeNode) {
        echo 'Found it! Depth was ' . $treeIterator->getDepth();
        break;
    }
}

@Swader
Copy link

Swader commented Sep 24, 2014

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants