Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DomCrawler] Inconsistency between children and parents #26432

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

Closed
dunglas opened this issue Mar 6, 2018 · 8 comments · Fixed by #39684
Closed

[DomCrawler] Inconsistency between children and parents #26432

dunglas opened this issue Mar 6, 2018 · 8 comments · Fixed by #39684

Comments

@dunglas
Copy link
Member

dunglas commented Mar 6, 2018

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version all

According to the documentation:

Get all the child or parent nodes:

$crawler->filter('body')->children();
$crawler->filter('body > p')->parents();

However, children() returns only direct children (not grandchildren...), while parents() returns all ancestors (including grandparents...).

Maybe it's more a docs issue than a code issue? Anyway it looks weird to me that methods with similar names have a different behavior.

@webnet-fr
Copy link
Contributor

Hi, I suppose that these methods replicate the functionality of jQuery. The children method returns direct children while parents returns all parents. IMHO another behaviour would increase WTF effect.
As to documentation it would be nice to precise that children method returns only direct children.

@jakzal
Copy link
Contributor

jakzal commented Mar 8, 2018

To be honest the current behaviour makes sense to me. It does say "children", not "descendants".

@dunglas
Copy link
Member Author

dunglas commented Mar 8, 2018

@jakzal I agree for this one, but why "parents" and not "ancestors" then?

@dunglas
Copy link
Member Author

dunglas commented Mar 8, 2018

In XPath, the terms are:

  • ancestor
  • parent

and

  • descendant
  • child

@Simperfit
Copy link
Contributor

Do close here and create the issue in the doc repo or is there something todo in core ?

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Friendly ping? Should this still be open? I will close if I don't hear anything.

@xabbuh
Copy link
Member

xabbuh commented Jan 2, 2021

see #39684

@carsonbot carsonbot removed the Stalled label Jan 2, 2021
@fabpot fabpot closed this as completed Jan 3, 2021
fabpot added a commit that referenced this issue Jan 3, 2021
…() (xabbuh)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[DomCrawler] deprecate parents() in favor of ancestors()

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | yes
| Tickets       | Fix #26432
| License       | MIT
| Doc PR        |

Commits
-------

8baafa2 deprecate parents() in favor of ancestors()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants