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).
where can i get some references about SPL predefined constants like SELF_FIRST , CHILD_FIRST
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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_ONLYiteration 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 areb,c,d,fandgsince 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):
The
RecursiveIteratorIterator::SELF_FIRSTiteration 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.
The
RecursiveIteratorIterator::CHILD_FIRSTiteration 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:
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
flagsargument which affects other behaviour like whether to halt if a child object throws an Exception, whether to call__toStringfor the items, etc. (the flags areCachingIteratorconstants, 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 constantto 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.