You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
siblings() raises warnings on an element with no parent #139
siblings() reads $m->parentNode->childNodes without checking for a parent, so calling it on an element that has no parent raises two warnings:
$doc = qp('<?xml version="1.0"?><root/>')->get(0)->ownerDocument;
$lone = $doc->createElement('lone');
qp($lone)->siblings()->count();
// Warning: Attempt to read property "childNodes" on null in src/Helpers/QueryFilters.php on line 1083// Warning: foreach() argument must be of type array|object, null given in src/Helpers/QueryFilters.php on line 1083// 0
The result (an empty set) is right, and matches jQuery 3.7.1 ($(document.createElement('lone')).siblings().length is 0). But the warnings are wrong, and become a fatal error under any error handler that converts warnings to exceptions (PHPUnit, Laravel, Symfony, ...). PHP 7.x raises the equivalent notice and warning.
An element in a detached subtree, which does have a parent, is fine: qp($a)->siblings() returns its siblings.
Expected
siblings() on an element with no parent returns an empty set, without warnings. contents() already guards with if (empty($m->childNodes)) continue;; siblings() needs the same check on $m->parentNode.
Found while reviewing #129, which fixed the same class of problem in parentsUntil() (an infinite loop on a detached element) by routing it through one walk helper. siblings() keeps its own loop there, so it was not covered.
Activity