-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DomCrawler] hasChildren() function #8048
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
Labels
Comments
Could you please provide a code example which would raise a notice? The following example works just fine even though h1 element doesn't have children: use Symfony\Component\DomCrawler\Crawler;
$crawler = new Crawler('<html><body><h1>Hello</h1><p>World!</p></body></html>');
$crawler = $crawler->filter('h1');
var_dump($crawler->children()->count() === 0); |
@jakzal, it doesn't have children of type |
fabpot
added a commit
that referenced
this issue
May 16, 2013
This PR was merged into the 2.1 branch. Discussion ---------- [DomCrawler] Fix Crawler::children() to not trigger a notice for childless node | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8048 | License | MIT | Doc PR | n/a Commits ------- 91b8490 Fix Crawler::children() to not trigger a notice for childless node
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's currently not possible to know if an element has children without getting notices when the input is an empty div:
(even when just doing $elem->children())
This is due to the call to the sibling function with:
An empty div has no firstChild so in the sibling function this generates the notice above.
One could fix this by adding a function such as:
The text was updated successfully, but these errors were encountered: