|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35734 RecursiveIteratorIterator constructor fails to recognize mode constants
Submitted: 2005-12-19 16:27 UTC Modified: 2005-12-19 19:31 UTC
From: dpantel at gmail dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.1.1 OS: RHES (linux 2.4.21-37)
Private report: No CVE-ID: None
 [2005-12-19 16:27 UTC] dpantel at gmail dot com
RecursiveIteratorIterator constructor fails to recognize mode constants.

The constructor works fine when passed only a RecursiveIterator object.  It also functions correctly if passed a RecursiveIterator object and an integer (0,1,2, etc) as the second (mode) argument.  However, if one attempts to pass a documented constant keyword (RIT_SELF_FIRST or SELF_FIRST), the constructor fails.

Note: different documentations show different constant definitions (RIT_SELF_FIRST vs SELF_FIRST). I have tried both, and neither one works.

Reproduce code:
class Rit implements RecursiveIterator {...}

$test = new Rit();

//work fine
$rii = new RecursiveIteratorIterator($test);
$rii = new RecursiveIteratorIterator($test, 1);

//do not work
$rii = new RecursiveIteratorIterator($test, RIT_SELF_FIRST);
$rii = new RecursiveIteratorIterator($test, SELF_FIRST);

//even tried this, with no avail
$rii = new RecursiveIteratorIterator($test, RecursiveIteratorIterator::RIT_SELF_FIRST);
$rii = new RecursiveIteratorIterator($test, RecursiveIteratorIterator::SELF_FIRST);

Expected result:
A RecursiveIteratorIterator object

Actual result:
Notice: Use of undefined constant RIT_SELF_FIRST - assumed 'RIT_SELF_FIRST' in /www/rit.class.php on line 276

(or Notice: Use of undefined constant SELF_FIRST - assumed 'SELF_FIRST' in /www/rit.class.php on line 276)

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'An instance of RecursiveIterator or IteratorAggregate creating it is required' in /www/rit.class.php:276 Stack trace: #0 /www/rit.class.php(276): RecursiveIteratorIterator->__construct(Object(treeIterator), 'RIT_SELF_FIRST') ...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-19 16:31 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Those are class constants now:


 [2005-12-19 16:38 UTC] dpantel at gmail dot com
If you take the time to read the bug report, you will notice that I have tried using `RecursiveIteratorIterator::SELF_FIRST` without success.
 [2005-12-19 19:29 UTC] dpantel at gmail dot com
My appologies.  I have recompiled PHP 5.1.1 and `RecursiveIteratorIterator::SELF_FIRST` now works.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Dec 14 12:01:26 2018 UTC