#27 Make sibling functions to accept index

open
nobody
None
5
2012-10-10
2011-07-21
Anonymous
No

So we could do something like:
$e->next_sibling()->next_sibling(6)->plaintext;
instead of:
$e->next_sibling()->next_sibling()->next_sibling()->next_sibling()->next_sibling()->next_sibling()->plaintext;

Thank you.

Discussion

  • nickl-
    nickl-
    2012-09-11

    You have a point there but I don't think next_sibling and prev_sibling should be changed, they are quite precise in what you'd expect from them.

    That said I can see a use, in line with our $e->children($idx) I would imagine we would find useful a $e->siblings($idx) method but if you think about it that doesn't make sense either, right?

    Why don't you use:
    $e->parent()->children(6)->plaintext;
    Instead which does exactly what you need, can already be done and has no ambiguity attached, do you agree?

    I was really keen for this idea but after writing out a solution it didn't make sense anymore. Just as $e->next_child() won't make sense because it's first_child not next_child unless it follows some iterator pattern perhaps. I'm really torn on this now.Maybe we should look at DomDocument or jQuery for examples?

    I will see if I can roll us something like that