Skip to content

Commit ed03532

Browse files
committed
Removed old child in replace child method
1 parent 5281c08 commit ed03532

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/PHPHtmlParser/Dom/InnerNode.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,18 @@ public function replaceChild(int $childId, AbstractNode $newChild): void
332332
'next' => $oldChild['next']
333333
);
334334

335+
// chnge previous child id to new child
335336
if ($oldChild['prev'] && isset($this->children[$newChild->prev])) {
336337
$this->children[$oldChild['prev']]['next'] = $newChild->id();
337338
}
338339

340+
// change next child id to new child
339341
if ($oldChild['next'] && isset($this->children[$newChild->next])) {
340342
$this->children[$oldChild['next']]['prev'] = $newChild->id();
341343
}
344+
345+
// remove old child
346+
unset($this->children[$childId]);
342347
}
343348

344349
/**

0 commit comments

Comments
 (0)