Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #34778 : DirectoryIterator::getType is inconsistent with filetype()
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 18th April 10:43
php-bugs
External User
 
Posts: 1
Default #34778 : DirectoryIterator::getType is inconsistent with filetype()



From: richard dot quadling at bandvulc dot co dot uk
Operating system: Windows XP SP2
PHP version: 5.0.5
PHP Bug Type: SPL related
Bug description: DirectoryIterator::getType is inconsistent with filetype()

Description:
------------
I'm using SPL RecursiveIteratorIterator, CachingRecursiveIterator and
RecursiveDirectoryIterator to get ALL the files in a directory structure.

Some of the files are being identied as directories when using
DirectoryIterator::getType() and comparing this to the result of
filetype().

Reproduce code:
---------------
<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
?>

Expected result:
----------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file file M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut to
ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk


Actual result:
--------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file dir M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut to
ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk


--
Edit bug report at http://bugs.php.net/?id=34778&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34778&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34778&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34778&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=34778&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=34778&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=34778&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=34778&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=34778&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34778&r=support
Expected behavior: http://bugs.php.net/fix.php?id=34778&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=34778&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=34778&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=34778&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34778&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=34778&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=34778&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34778&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=34778&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=34778&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=34778&r=mysqlcfg
  Reply With Quote


  sponsored links


2 18th April 10:43
php-bugs
External User
 
Posts: 1
Default #34778 : DirectoryIterator::getType is inconsistent with filetype()



ID: 34778
User updated by: richard dot quadling at bandvulc dot co dot uk
Reported By: richard dot quadling at bandvulc dot co dot uk
Status: Open
Bug Type: SPL related
Operating System: Windows XP SP2
PHP Version: 5.0.5
New Comment:

I altered the code just to show those that are different ...

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
if (filetype($sKey) != $objValue->getType())
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
}
?>

and get things like ...

dir file M:/Datastore/Bandvulc Department Desktops/Sales/bij1100
file dir M:/Datastore/Bandvulc Department
Desktops/Sales/bij1100/win2k_xp/english/hpzvip09.dl_

Here we see a directory (filetype()) which the next line is a file
within that directory and that line is being shown as a directory when
in fact it is obviously a folder.


Previous Comments:
------------------------------------------------------------------------

[2005-10-07 13:41:59] richard dot quadling at bandvulc dot co dot uk

Description:
------------
I'm using SPL RecursiveIteratorIterator, CachingRecursiveIterator and
RecursiveDirectoryIterator to get ALL the files in a directory
structure.

Some of the files are being identied as directories when using
DirectoryIterator::getType() and comparing this to the result of
filetype().

Reproduce code:
---------------
<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
?>

Expected result:
----------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file file M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut
to ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk


Actual result:
--------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file dir M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut to
ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk

------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=34778&edit=1
  Reply With Quote
3 18th April 10:44
External User
 
Posts: 1
Default #34778 : DirectoryIterator::getType is inconsistent with filetype()


ID: 34778
Updated by: sniper@php.net
Reported By: richard dot quadling at bandvulc dot co dot uk
-Status: Open
+Status: Feedback
Bug Type: SPL related
Operating System: Windows XP SP2
PHP Version: 5.0.5
New Comment:

Please try using this CVS snapshot:

http://snaps.php.net/php5-latest.tar.gz

For Windows:

http://snaps.php.net/win32/php5-win32-latest.zip


Previous Comments:
------------------------------------------------------------------------

[2005-10-07 14:05:18] richard dot quadling at bandvulc dot co dot uk

I altered the code just to show those that are different ...

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
if (filetype($sKey) != $objValue->getType())
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
}
?>

and get things like ...

dir file M:/Datastore/Bandvulc Department Desktops/Sales/bij1100
file dir M:/Datastore/Bandvulc Department
Desktops/Sales/bij1100/win2k_xp/english/hpzvip09.dl_

Here we see a directory (filetype()) which the next line is a file
within that directory and that line is being shown as a directory when
in fact it is obviously a folder.

------------------------------------------------------------------------

[2005-10-07 13:41:59] richard dot quadling at bandvulc dot co dot uk

Description:
------------
I'm using SPL RecursiveIteratorIterator, CachingRecursiveIterator and
RecursiveDirectoryIterator to get ALL the files in a directory
structure.

Some of the files are being identied as directories when using
DirectoryIterator::getType() and comparing this to the result of
filetype().

Reproduce code:
---------------
<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
?>

Expected result:
----------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file file M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut
to ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk


Actual result:
--------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file dir M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut to
ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk

------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=34778&edit=1
  Reply With Quote
4 18th April 11:06
External User
 
Posts: 1
Default #34778 : DirectoryIterator::getType is inconsistent with filetype()


ID: 34778
Updated by: helly@php.net
Reported By: richard dot quadling at bandvulc dot co dot uk
-Status: Feedback
+Status: Bogus
Bug Type: SPL related
Operating System: Windows XP SP2
PHP Version: 5.0.5
New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

Since you are using a CachingIterator and access the type through it
the result is expected.

What happens is that the Caching iterator aggrgates the
DirectoryIterator. So when you access a value from a method of the
Directory iterator it is executed on the DirectoryIteraotr. But the
DirectoryIteraotr has already changed it's state.

To solve this issue, you would need to cache all the information by
deriving the CachingIterator.


Previous Comments:
------------------------------------------------------------------------

[2005-10-07 15:39:25] sniper@php.net

Please try using this CVS snapshot:

http://snaps.php.net/php5-latest.tar.gz

For Windows:

http://snaps.php.net/win32/php5-win32-latest.zip

------------------------------------------------------------------------

[2005-10-07 14:05:18] richard dot quadling at bandvulc dot co dot uk

I altered the code just to show those that are different ...

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
if (filetype($sKey) != $objValue->getType())
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
}
?>

and get things like ...

dir file M:/Datastore/Bandvulc Department Desktops/Sales/bij1100
file dir M:/Datastore/Bandvulc Department
Desktops/Sales/bij1100/win2k_xp/english/hpzvip09.dl_

Here we see a directory (filetype()) which the next line is a file
within that directory and that line is being shown as a directory when
in fact it is obviously a folder.

------------------------------------------------------------------------

[2005-10-07 13:41:59] richard dot quadling at bandvulc dot co dot uk

Description:
------------
I'm using SPL RecursiveIteratorIterator, CachingRecursiveIterator and
RecursiveDirectoryIterator to get ALL the files in a directory
structure.

Some of the files are being identied as directories when using
DirectoryIterator::getType() and comparing this to the result of
filetype().

Reproduce code:
---------------
<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
?>

Expected result:
----------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file file M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut
to ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk


Actual result:
--------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file dir M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut to
ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk

------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=34778&edit=1
  Reply With Quote
5 18th April 20:41
php-bugs
External User
 
Posts: 1
Default #34778 : DirectoryIterator::getType is inconsistent with filetype()


ID: 34778
User updated by: richard dot quadling at bandvulc dot co dot uk
Reported By: richard dot quadling at bandvulc dot co dot uk
Status: Bogus
Bug Type: SPL related
Operating System: Windows XP SP2
PHP Version: 5.0.5
New Comment:

What I don't understand is why the state is incorrect only on SOME of
the results and not all the results.

Or am I doing the whole thing wrong?

Is there a better set of user do***entation for these classes. I get
very confused. I shouldn't. I've been doing this for long enough. But I
do. I'm getting old. Nearly 40 you know. So, be nice to the old man.

I want to use OOP to get all the files and directories from a start
point. I also want to add a filter to only return certain files based
upon their extension. I don't know the correct way to combine the
different classes.

Sorry.


Previous Comments:
------------------------------------------------------------------------

[2005-10-07 20:17:48] helly@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

Since you are using a CachingIterator and access the type through it
the result is expected.

What happens is that the Caching iterator aggrgates the
DirectoryIterator. So when you access a value from a method of the
Directory iterator it is executed on the DirectoryIteraotr. But the
DirectoryIteraotr has already changed it\'s state.

To solve this issue, you would need to cache all the information by
deriving the CachingIterator.

------------------------------------------------------------------------

[2005-10-07 15:39:25] sniper@php.net

Please try using this CVS snapshot:

http://snaps.php.net/php5-latest.tar.gz

For Windows:

http://snaps.php.net/win32/php5-win32-latest.zip

------------------------------------------------------------------------

[2005-10-07 14:05:18] richard dot quadling at bandvulc dot co dot uk

I altered the code just to show those that are different ...

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
if (filetype($sKey) != $objValue->getType())
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
}
?>

and get things like ...

dir file M:/Datastore/Bandvulc Department Desktops/Sales/bij1100
file dir M:/Datastore/Bandvulc Department
Desktops/Sales/bij1100/win2k_xp/english/hpzvip09.dl_

Here we see a directory (filetype()) which the next line is a file
within that directory and that line is being shown as a directory when
in fact it is obviously a folder.

------------------------------------------------------------------------

[2005-10-07 13:41:59] richard dot quadling at bandvulc dot co dot uk

Description:
------------
I'm using SPL RecursiveIteratorIterator, CachingRecursiveIterator and
RecursiveDirectoryIterator to get ALL the files in a directory
structure.

Some of the files are being identied as directories when using
DirectoryIterator::getType() and comparing this to the result of
filetype().

Reproduce code:
---------------
<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
?>

Expected result:
----------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file file M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut
to ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk


Actual result:
--------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file dir M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut to
ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk

------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=34778&edit=1
  Reply With Quote
6 18th April 20:41
php-bugs
External User
 
Posts: 1
Default #34778 : DirectoryIterator::getType is inconsistent with filetype()


ID: 34778
User updated by: richard dot quadling at bandvulc dot co dot uk
Reported By: richard dot quadling at bandvulc dot co dot uk
-Status: Bogus
+Status: Open
Bug Type: SPL related
Operating System: Windows XP SP2
PHP Version: 5.0.5
New Comment:

Ok (I didn't understand the answer as I don't know why the caching
should have any difference).

I think I found my problem.

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('C:/test/');

$iTotal = 0;
$iRight = 0;
$iWrong = 0;
foreach($objDIR as $sKey => $objValue)
{
++$iTotal;
echo $iTotal . ' ' . filetype($sKey) . ' ' . $objValue->getType() . '
' . $sKey . ' ' . $objValue . "\n";
if (filetype($sKey) != $objValue->getType())
{
++$iWrong;
}
else
{
++$iRight;
}
}
echo "Total : $iTotal\nRight : $iRight\nWrong : $iWrong\n";
?>

The directory test contains 1 file.

1 file dir C:/test/file1.txt Object id #3
Total : 1
Right : 0
Wrong : 1

This implies that the foreach() mechanism returns the current item for
a key but the next entry for the value.

Which is very much NOT what I would expect. I would expect the key to
be the filename (as it is) and the value to be the object representing
the filename.

The question that comes from this is how do I get the object which is
the FIRST file?

Richard.


Previous Comments:
------------------------------------------------------------------------

[2005-10-11 14:53:14] richard dot quadling at bandvulc dot co dot uk

What I don't understand is why the state is incorrect only on SOME of
the results and not all the results.

Or am I doing the whole thing wrong?

Is there a better set of user do***entation for these classes. I get
very confused. I shouldn't. I've been doing this for long enough. But I
do. I'm getting old. Nearly 40 you know. So, be nice to the old man.

I want to use OOP to get all the files and directories from a start
point. I also want to add a filter to only return certain files based
upon their extension. I don't know the correct way to combine the
different classes.

Sorry.

------------------------------------------------------------------------

[2005-10-07 20:17:48] helly@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

Since you are using a CachingIterator and access the type through it
the result is expected.

What happens is that the Caching iterator aggrgates the
DirectoryIterator. So when you access a value from a method of the
Directory iterator it is executed on the DirectoryIteraotr. But the
DirectoryIteraotr has already changed it\'s state.

To solve this issue, you would need to cache all the information by
deriving the CachingIterator.

------------------------------------------------------------------------

[2005-10-07 15:39:25] sniper@php.net

Please try using this CVS snapshot:

http://snaps.php.net/php5-latest.tar.gz

For Windows:

http://snaps.php.net/win32/php5-win32-latest.zip

------------------------------------------------------------------------

[2005-10-07 14:05:18] richard dot quadling at bandvulc dot co dot uk

I altered the code just to show those that are different ...

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
if (filetype($sKey) != $objValue->getType())
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
}
?>

and get things like ...

dir file M:/Datastore/Bandvulc Department Desktops/Sales/bij1100
file dir M:/Datastore/Bandvulc Department
Desktops/Sales/bij1100/win2k_xp/english/hpzvip09.dl_

Here we see a directory (filetype()) which the next line is a file
within that directory and that line is being shown as a directory when
in fact it is obviously a folder.

------------------------------------------------------------------------

[2005-10-07 13:41:59] richard dot quadling at bandvulc dot co dot uk

Description:
------------
I'm using SPL RecursiveIteratorIterator, CachingRecursiveIterator and
RecursiveDirectoryIterator to get ALL the files in a directory
structure.

Some of the files are being identied as directories when using
DirectoryIterator::getType() and comparing this to the result of
filetype().

Reproduce code:
---------------
<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
?>

Expected result:
----------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file file M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut
to ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk


Actual result:
--------------
dir dir M:/Datastore/Bandvulc Department Desktops
dir dir M:/Datastore/Bandvulc Department Desktops/Accounts
file dir M:/Datastore/Bandvulc Department Desktops/Accounts/Shortcut to
ECDL.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Bandvulc Tyre Contracts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Salvesen Europe Contacts.lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Sinead Williams on bandsbs.lnk
file dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Shortcut to Strike Rates 2005.lnk
dir dir M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v1).lnk
file file M:/Datastore/Bandvulc Department Desktops/Bandvulc Tyre
Contracts/Unused Desktop Shortcuts/Access Accounts (btc v2).lnk

------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=34778&edit=1
  Reply With Quote
7 18th April 20:41
External User
 
Posts: 1
Default #34778 : DirectoryIterator::getType is inconsistent with filetype()


ID: 34778
Updated by: iliaa@php.net
Reported By: richard dot quadling at bandvulc dot co dot uk
-Status: Open
+Status: Assigned
Bug Type: SPL related
Operating System: Windows XP SP2
PHP Version: 5.0.5
-Assigned To:
+Assigned To: helly


Previous Comments:
------------------------------------------------------------------------

[2005-10-11 15:12:57] richard dot quadling at bandvulc dot co dot uk

Ok (I didn't understand the answer as I don't know why the caching
should have any difference).

I think I found my problem.

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('C:/test/');

$iTotal = 0;
$iRight = 0;
$iWrong = 0;
foreach($objDIR as $sKey => $objValue)
{
++$iTotal;
echo $iTotal . ' ' . filetype($sKey) . ' ' . $objValue->getType() . '
' . $sKey . ' ' . $objValue . "\n";
if (filetype($sKey) != $objValue->getType())
{
++$iWrong;
}
else
{
++$iRight;
}
}
echo "Total : $iTotal\nRight : $iRight\nWrong : $iWrong\n";
?>

The directory test contains 1 file.

1 file dir C:/test/file1.txt Object id #3
Total : 1
Right : 0
Wrong : 1

This implies that the foreach() mechanism returns the current item for
a key but the next entry for the value.

Which is very much NOT what I would expect. I would expect the key to
be the filename (as it is) and the value to be the object representing
the filename.

The question that comes from this is how do I get the object which is
the FIRST file?

Richard.

------------------------------------------------------------------------

[2005-10-11 14:53:14] richard dot quadling at bandvulc dot co dot uk

What I don't understand is why the state is incorrect only on SOME of
the results and not all the results.

Or am I doing the whole thing wrong?

Is there a better set of user do***entation for these classes. I get
very confused. I shouldn't. I've been doing this for long enough. But I
do. I'm getting old. Nearly 40 you know. So, be nice to the old man.

I want to use OOP to get all the files and directories from a start
point. I also want to add a filter to only return certain files based
upon their extension. I don't know the correct way to combine the
different classes.

Sorry.

------------------------------------------------------------------------

[2005-10-07 20:17:48] helly@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

Since you are using a CachingIterator and access the type through it
the result is expected.

What happens is that the Caching iterator aggrgates the
DirectoryIterator. So when you access a value from a method of the
Directory iterator it is executed on the DirectoryIteraotr. But the
DirectoryIteraotr has already changed it\'s state.

To solve this issue, you would need to cache all the information by
deriving the CachingIterator.

------------------------------------------------------------------------

[2005-10-07 15:39:25] sniper@php.net

Please try using this CVS snapshot:

http://snaps.php.net/php5-latest.tar.gz

For Windows:

http://snaps.php.net/win32/php5-win32-latest.zip

------------------------------------------------------------------------

[2005-10-07 14:05:18] richard dot quadling at bandvulc dot co dot uk

I altered the code just to show those that are different ...

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
if (filetype($sKey) != $objValue->getType())
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
}
?>

and get things like ...

dir file M:/Datastore/Bandvulc Department Desktops/Sales/bij1100
file dir M:/Datastore/Bandvulc Department
Desktops/Sales/bij1100/win2k_xp/english/hpzvip09.dl_

Here we see a directory (filetype()) which the next line is a file
within that directory and that line is being shown as a directory when
in fact it is obviously a folder.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/34778

--
Edit this bug report at http://bugs.php.net/?id=34778&edit=1
  Reply With Quote
8 18th April 22:19
External User
 
Posts: 1
Default #34778 : DirectoryIterator::getType is inconsistent with filetype()


ID: 34778
Updated by: helly@php.net
Reported By: richard dot quadling at bandvulc dot co dot uk
-Status: Assigned
+Status: Bogus
Bug Type: SPL related
-Operating System: Windows XP SP2
+Operating System: *
PHP Version: 5.0.5
Assigned To: helly
New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

As i explained there is no error in PHP.

This is actually a 30cm problem.


Previous Comments:
------------------------------------------------------------------------

[2005-10-11 15:12:57] richard dot quadling at bandvulc dot co dot uk

Ok (I didn't understand the answer as I don't know why the caching
should have any difference).

I think I found my problem.

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('C:/test/');

$iTotal = 0;
$iRight = 0;
$iWrong = 0;
foreach($objDIR as $sKey => $objValue)
{
++$iTotal;
echo $iTotal . ' ' . filetype($sKey) . ' ' . $objValue->getType() . '
' . $sKey . ' ' . $objValue . "\n";
if (filetype($sKey) != $objValue->getType())
{
++$iWrong;
}
else
{
++$iRight;
}
}
echo "Total : $iTotal\nRight : $iRight\nWrong : $iWrong\n";
?>

The directory test contains 1 file.

1 file dir C:/test/file1.txt Object id #3
Total : 1
Right : 0
Wrong : 1

This implies that the foreach() mechanism returns the current item for
a key but the next entry for the value.

Which is very much NOT what I would expect. I would expect the key to
be the filename (as it is) and the value to be the object representing
the filename.

The question that comes from this is how do I get the object which is
the FIRST file?

Richard.

------------------------------------------------------------------------

[2005-10-11 14:53:14] richard dot quadling at bandvulc dot co dot uk

What I don't understand is why the state is incorrect only on SOME of
the results and not all the results.

Or am I doing the whole thing wrong?

Is there a better set of user do***entation for these classes. I get
very confused. I shouldn't. I've been doing this for long enough. But I
do. I'm getting old. Nearly 40 you know. So, be nice to the old man.

I want to use OOP to get all the files and directories from a start
point. I also want to add a filter to only return certain files based
upon their extension. I don't know the correct way to combine the
different classes.

Sorry.

------------------------------------------------------------------------

[2005-10-07 20:17:48] helly@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

Since you are using a CachingIterator and access the type through it
the result is expected.

What happens is that the Caching iterator aggrgates the
DirectoryIterator. So when you access a value from a method of the
Directory iterator it is executed on the DirectoryIteraotr. But the
DirectoryIteraotr has already changed it\'s state.

To solve this issue, you would need to cache all the information by
deriving the CachingIterator.

------------------------------------------------------------------------

[2005-10-07 15:39:25] sniper@php.net

Please try using this CVS snapshot:

http://snaps.php.net/php5-latest.tar.gz

For Windows:

http://snaps.php.net/win32/php5-win32-latest.zip

------------------------------------------------------------------------

[2005-10-07 14:05:18] richard dot quadling at bandvulc dot co dot uk

I altered the code just to show those that are different ...

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
if (filetype($sKey) != $objValue->getType())
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
}
?>

and get things like ...

dir file M:/Datastore/Bandvulc Department Desktops/Sales/bij1100
file dir M:/Datastore/Bandvulc Department
Desktops/Sales/bij1100/win2k_xp/english/hpzvip09.dl_

Here we see a directory (filetype()) which the next line is a file
within that directory and that line is being shown as a directory when
in fact it is obviously a folder.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/34778

--
Edit this bug report at http://bugs.php.net/?id=34778&edit=1
  Reply With Quote
9 18th April 22:20
php-bugs
External User
 
Posts: 1
Default #34778 : DirectoryIterator::getType is inconsistent with filetype()


ID: 34778
User updated by: richard dot quadling at bandvulc dot co dot uk
Reported By: richard dot quadling at bandvulc dot co dot uk
-Status: Bogus
+Status: Open
Bug Type: SPL related
Operating System: *
PHP Version: 5.0.5
Assigned To: helly
New Comment:

What? A 30cm problem? What does that mean?

In plain english, why is this not a bug?

You understand this domain very well. I don't. At least tell me why
this is not correct. Why should the last example I supplied be
considered CORRECT? It does not give expected results, there is no
do***entation on the class and so any behaviour is valid. Is that why?

Richard.


Previous Comments:
------------------------------------------------------------------------

[2005-10-11 20:14:13] helly@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

As i explained there is no error in PHP.

This is actually a 30cm problem.

------------------------------------------------------------------------

[2005-10-11 15:12:57] richard dot quadling at bandvulc dot co dot uk

Ok (I didn't understand the answer as I don't know why the caching
should have any difference).

I think I found my problem.

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('C:/test/');

$iTotal = 0;
$iRight = 0;
$iWrong = 0;
foreach($objDIR as $sKey => $objValue)
{
++$iTotal;
echo $iTotal . ' ' . filetype($sKey) . ' ' . $objValue->getType() . '
' . $sKey . ' ' . $objValue . "\n";
if (filetype($sKey) != $objValue->getType())
{
++$iWrong;
}
else
{
++$iRight;
}
}
echo "Total : $iTotal\nRight : $iRight\nWrong : $iWrong\n";
?>

The directory test contains 1 file.

1 file dir C:/test/file1.txt Object id #3
Total : 1
Right : 0
Wrong : 1

This implies that the foreach() mechanism returns the current item for
a key but the next entry for the value.

Which is very much NOT what I would expect. I would expect the key to
be the filename (as it is) and the value to be the object representing
the filename.

The question that comes from this is how do I get the object which is
the FIRST file?

Richard.

------------------------------------------------------------------------

[2005-10-11 14:53:14] richard dot quadling at bandvulc dot co dot uk

What I don't understand is why the state is incorrect only on SOME of
the results and not all the results.

Or am I doing the whole thing wrong?

Is there a better set of user do***entation for these classes. I get
very confused. I shouldn't. I've been doing this for long enough. But I
do. I'm getting old. Nearly 40 you know. So, be nice to the old man.

I want to use OOP to get all the files and directories from a start
point. I also want to add a filter to only return certain files based
upon their extension. I don't know the correct way to combine the
different classes.

Sorry.

------------------------------------------------------------------------

[2005-10-07 20:17:48] helly@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

Since you are using a CachingIterator and access the type through it
the result is expected.

What happens is that the Caching iterator aggrgates the
DirectoryIterator. So when you access a value from a method of the
Directory iterator it is executed on the DirectoryIteraotr. But the
DirectoryIteraotr has already changed it\'s state.

To solve this issue, you would need to cache all the information by
deriving the CachingIterator.

------------------------------------------------------------------------

[2005-10-07 14:05:18] richard dot quadling at bandvulc dot co dot uk

I altered the code just to show those that are different ...

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('M:/Datastore');

foreach($objDIR as $sKey => &$objValue)
{
if (filetype($sKey) != $objValue->getType())
{
echo filetype($sKey) . ' ' . $objValue->getType() . " $sKey\n";
}
}
?>

and get things like ...

dir file M:/Datastore/Bandvulc Department Desktops/Sales/bij1100
file dir M:/Datastore/Bandvulc Department
Desktops/Sales/bij1100/win2k_xp/english/hpzvip09.dl_

Here we see a directory (filetype()) which the next line is a file
within that directory and that line is being shown as a directory when
in fact it is obviously a folder.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/34778

--
Edit this bug report at http://bugs.php.net/?id=34778&edit=1
  Reply With Quote
10 19th April 00:23
External User
 
Posts: 1
Default #34778 : DirectoryIterator::getType is inconsistent with filetype()


ID: 34778
Updated by: helly@php.net
Reported By: richard dot quadling at bandvulc dot co dot uk
-Status: Open
+Status: Bogus
Bug Type: SPL related
Operating System: *
PHP Version: 5.0.5
Assigned To: helly
New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

Please do not reopen this bug. THERE IS NO BUG. You are turning the bug
database into a mess.

And i explained it already:

<quote>
What happens is that the Caching iterator aggrgates the
DirectoryIterator. So when you access a value from a method of the
Directory iterator it is executed on the DirectoryIteraotr. But the
DirectoryIteraotr has already changed it's state.

To solve this issue, you would need to cache all the information by
deriving the CachingIterator.
</quote>

class MyDirectoryIterator
{
function current()
{
return $this->getFilename();
// the implementation in DirectoryIterator does
// return $this;
}
}


Previous Comments:
------------------------------------------------------------------------

[2005-10-12 12:03:27] richard dot quadling at bandvulc dot co dot uk

What? A 30cm problem? What does that mean?

In plain english, why is this not a bug?

You understand this domain very well. I don't. At least tell me why
this is not correct. Why should the last example I supplied be
considered CORRECT? It does not give expected results, there is no
do***entation on the class and so any behaviour is valid. Is that why?

Richard.

------------------------------------------------------------------------

[2005-10-11 20:14:13] helly@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

As i explained there is no error in PHP.

This is actually a 30cm problem.

------------------------------------------------------------------------

[2005-10-11 15:12:57] richard dot quadling at bandvulc dot co dot uk

Ok (I didn't understand the answer as I don't know why the caching
should have any difference).

I think I found my problem.

<?php
class class_DirectoryWalker extends RecursiveIteratorIterator
{
function __construct($path)
{
parent::__construct(new CachingRecursiveIterator(new
RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING |
CIT_CATCH_GET_CHILD), 1);
}

function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(), $func),
$params);
}
}

$objDIR = new class_DirectoryWalker('C:/test/');

$iTotal = 0;
$iRight = 0;
$iWrong = 0;
foreach($objDIR as $sKey => $objValue)
{
++$iTotal;
echo $iTotal . ' ' . filetype($sKey) . ' ' . $objValue->getType() . '
' . $sKey . ' ' . $objValue . "\n";
if (filetype($sKey) != $objValue->getType())
{
++$iWrong;
}
else
{
++$iRight;
}
}
echo "Total : $iTotal\nRight : $iRight\nWrong : $iWrong\n";
?>

The directory test contains 1 file.

1 file dir C:/test/file1.txt Object id #3
Total : 1
Right : 0
Wrong : 1

This implies that the foreach() mechanism returns the current item for
a key but the next entry for the value.

Which is very much NOT what I would expect. I would expect the key to
be the filename (as it is) and the value to be the object representing
the filename.

The question that comes from this is how do I get the object which is
the FIRST file?

Richard.

------------------------------------------------------------------------

[2005-10-11 14:53:14] richard dot quadling at bandvulc dot co dot uk

What I don't understand is why the state is incorrect only on SOME of
the results and not all the results.

Or am I doing the whole thing wrong?

Is there a better set of user do***entation for these classes. I get
very confused. I shouldn't. I've been doing this for long enough. But I
do. I'm getting old. Nearly 40 you know. So, be nice to the old man.

I want to use OOP to get all the files and directories from a start
point. I also want to add a filter to only return certain files based
upon their extension. I don't know the correct way to combine the
different classes.

Sorry.

------------------------------------------------------------------------

[2005-10-07 20:17:48] helly@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the do***entation 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

Since you are using a CachingIterator and access the type through it
the result is expected.

What happens is that the Caching iterator aggrgates the
DirectoryIterator. So when you access a value from a method of the
Directory iterator it is executed on the DirectoryIteraotr. But the
DirectoryIteraotr has already changed it\'s state.

To solve this issue, you would need to cache all the information by
deriving the CachingIterator.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/34778

--
Edit this bug report at http://bugs.php.net/?id=34778&edit=1
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666