Walker enters infinite loop. #660
-
When I run this code (https://gist.github.com/fiddlerwoaroof/b24809107dfb81dc6c8d#file-test-php), the walker gets stuck in a loop between the inserted child and the parent element. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The walker emits two events for the Try modifying your debug code to something like this: $direction = $event->isEntering() ? "Entering" : "Leaving";
$nodeClass = get_class($node);
printf("%s the %s element\n", $direction, $nodeClass); And you'll see the following output:
You can fix your code by changing line 28 from this: if ($node instanceof Emphasis) { To this: if ($node instanceof Emphasis && $event->isEntering()) { |
Beta Was this translation helpful? Give feedback.
The walker emits two events for the
Emphasis
object: once when it enters, and again when it leaves. Your code is adding a newText
element both times and continuously resetting the walker's position just prior to it exiting theEmphasis
object. Two iterations later it's exiting theEmphasis
again, and your code adds theText
and resets the position again. This cycle repeats indefinitely.Try modifying your debug code to something like this:
And you'll see the following output: