Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 679061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:13:06+00:00 2026-05-14T01:13:06+00:00

where can i get some references about SPL predefined constants like SELF_FIRST , CHILD_FIRST

  • 0

where can i get some references about SPL predefined constants like SELF_FIRST,CHILD_FIRST ? on php.net i don’t get much(just their type).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:13:06+00:00Added an answer on May 14, 2026 at 1:13 am

    I’ll outline (some of) the class constants from the page you linked to then raise a few other points.

    RecursiveIteratorIterator iteration modes


    The RecursiveIteratorIterator::LEAVES_ONLY iteration mode. (This is the default mode.)

    This iteration mode (one of three) restricts the items available during iteration to only the “leaves” (think of a recursive structure as a tree with a series of branches sprouting other branches or, in the case of no more branches, having leaves on the end). In the array array('a'=>array('b','c'),'d','e'=>array('f','g')) the leaves are b,c,d,f and g since they are at the end, they do not sprout any more items.

    To give a code snippet showing this mode in action (There will be a series of examples having the same recursive array iterator with a recursive iterator iterator using different modes and flags):

    $array = array('a'=>array('b','c'),'d','e'=>array('f','g'));
    $ait   = new RecursiveArrayIterator($array);
    
    // Only iterate over leaves
    $rit   = new RecursiveIteratorIterator($ait, RecursiveIteratorIterator::LEAVES_ONLY);
    foreach ($rit as $item) {
        echo $item;
    }
    // Output: bcdfg
    

    The RecursiveIteratorIterator::SELF_FIRST iteration mode.

    This iteration mode instructs the iterator that the “parent” items (i.e. not leaves) are to be placed before their children (if any) when iterating.

    // Parents come first
    $rit   = new RecursiveIteratorIterator($ait, RecursiveIteratorIterator::SELF_FIRST);
    foreach ($rit as $key => $item) {
        if (is_array($item)) echo "[$key]"; // parent
        else echo $item;                    // child
    }
    // Output: [a]bcd[e]fg
    

    The RecursiveIteratorIterator::CHILD_FIRST iteration mode.

    This iteration mode swaps around the parent/child positions such that the children items (leaves) come first, followed by the parent as demonstrated by:

    // Children first
    $rit   = new RecursiveIteratorIterator($ait, RecursiveIteratorIterator::CHILD_FIRST);
    foreach ($rit as $key => $item) {
        if (is_array($item)) echo "[$key]"; // parent
        else echo $item;                    // child
    }
    // Output: bc[a]dfg[e]
    

    Other points

    RecursiveIteratorIterator constructor flags

    Those are only the constants for the three modes (leaves only, parent first or child first) of iterating over recursive iterators. The RecursiveIteratorIterator also has a flags argument which affects other behaviour like whether to halt if a child object throws an Exception, whether to call __toString for the items, etc. (the flags are CachingIterator constants, which are equally undocumented).

    Other SPL constants

    This ties in with my next point. There is no single, one-stop spot which lists all of the constants available throughout the SPL: most of the classes do not even list their own constants. You can however use reflection to take a peek at available constants. On the command line use something like php --rc recursiveiteratoriterator | grep -i constant to see a list of the RecursiveIteratorIterator’s constants.

    Lack of documentation

    The documentation available in the PHP manual is written (pretty much) entirely by volunteers. The SPL in particular is a sore spot with there still being a huge amount of work to do before that area is ship-shape and up-to-standard. If anyone wants to help in that (not sure if SO would consider this advertising?) then contact me (salathe@php.net) or sign up to the PHP documentation mailing list (send a blank email to phpdoc-subscribe@lists.php.net) and get stuck in. The more, the merrier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 371k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need a middleware that can execute code after the… May 14, 2026 at 7:00 pm
  • Editorial Team
    Editorial Team added an answer You could do something (ugly) like this: pseudo code: /**… May 14, 2026 at 7:00 pm
  • Editorial Team
    Editorial Team added an answer Your analysis of the problem ("it only work if the… May 14, 2026 at 7:00 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.