php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41975 SELF_FIRST constant missing
Submitted: 2007-07-12 07:04 UTC Modified: 2007-07-12 10:07 UTC
From: kevin at oceania dot net Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5CVS-2007-07-12 (snap) OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kevin at oceania dot net
New email:
PHP Version: OS:

 

 [2007-07-12 07:04 UTC] kevin at oceania dot net
Description:
------------
When calling parent::SELF_FIRST with recursiveDirectoryIterator fatal error

Reproduce code:
---------------
<?php
class DirectoryTreeIterator extends RecursiveDirectoryIterator{

public function __construct($path) {  parent::__construct(new RecursiveCachingIterator(
 new RecursiveDirectoryIterator($path,
 RecursiveDirectoryIterator::KEY_AS_FILENAME),
 CachingIterator::CALL_TOSTRING),
 parent::SELF_FIRST);
}

public function current() {
 $cur = "";
 for( $i = 0; $i < $this->getDepth(); $i++)
        {
        $cur .= $this->getSubIterator($i)->hasNext() ? " | " : " ";
        }
 $i = $this->SubIterator($i);
 return $cur . ($i->hasNext() ? " | - " : "/ - ").(string)$i;
}

} /*** end of class ***/

$obj = new DirectoryTreeIterator('albums');

Expected result:
----------------
directory list

Actual result:
--------------
Fatal error: Undefined class constant 'SELF_FIRST' in /www/web/test.php on line 9

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-12 09:11 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

RecursiveDirectoryIterator doesn't know about recursive iteration process so it does not have a const SELF_FIRST. That is the domain of RecursiveIteratorIterator. So you have to d:

new RII(new RCI(new RDI(...)))

there is: spl/examples/recursivetreeiterator.inc

which generalizes the handling of the tree graphics. But it works a bit different. IT is an extended RecursiveIteratorIterator, so infact it does know what to do with const SELF_FIRST. And it also handles the caching automatically. Maybe we should put that into the extension finally.
 [2007-07-12 10:07 UTC] kevin at oceania dot net
Ok, I took the code from your vancouver 200702 spl update slide.

Thanks
Kevin
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 02:01:30 2024 UTC