Bug #73488 [Fbk->Csd]: DirectoryIterator::isDir() strange behavior

From: Date: Thu, 10 Nov 2016 16:17:53 +0000
Subject: Bug #73488 [Fbk->Csd]: DirectoryIterator::isDir() strange behavior
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205287@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73488&edit=1 ID: 73488 User updated by: stan dot wanderer at gmail dot com Reported by: stan dot wanderer at gmail dot com Summary: DirectoryIterator::isDir() strange behavior -Status: Feedback +Status: Closed Type: Bug Package: *Directory/Filesystem functions Operating System: ubuntu 16.04.1 lts x64 PHP Version: 7.0.13 Block user comment: N Private report: N New Comment: Very interesting :) Don't use Iterators as plain object - I understood... Thanks for your answer! I think this issue can be closed Previous Comments: ------------------------------------------------------------------------ [2016-11-10 16:06:41] requinix@php.net As its name says, DirectoryIterator iterates over a directory. It does not represent the directory itself. It should thus come as no surprise that isDir will return whether the current item is a directory. Try this: foreach (scandir(__DIR__) as $f) { if (is_dir($f)) { $di = new DirectoryIterator($f); echo sprintf("%30s: %d\n", $di->getPathname(), $di->isDir()); } } ------------------------------------------------------------------------ [2016-11-10 15:45:31] stan dot wanderer at gmail dot com Description: ------------ hello, I've noticed that the DirectoryIterator object (as I know extended from SplFileInfo) has strange behavior of method isDir() - random boolean result on real directories. I've tried to run my tests on different environments (the same results): Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-45-generic x86_64) # php -v PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies Ubuntu 14.04.5 LTS (GNU/Linux 4.8.3-x86_64-linode76 x86_64) # php -v PHP 5.5.9-1ubuntu4.19 (cli) (built: Jul 28 2016 19:31:33) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies Maybe it is not a bug, but I cannot find any information about this issue. Please, contact with me if you need any additional information. Hope this will make PHP better! Test script: --------------- <?php foreach (scandir(__DIR__) as $f) if (is_dir($f)) echo sprintf("%20s: %d\n", $f, (new DirectoryIterator($f))->isDir()); Expected result: ---------------- bin: 1 boot: 1 dev: 1 etc: 1 home: 1 lib: 1 lib64: 1 lost+found: 1 media: 1 mnt: 1 opt: 1 proc: 1 root: 1 run: 1 sbin: 1 srv: 1 sys: 1 tmp: 1 usr: 1 var: 1 Actual result: -------------- bin: 0 boot: 1 dev: 1 etc: 0 home: 1 lib: 1 lib64: 0 lost+found: 1 media: 1 mnt: 1 opt: 1 proc: 1 root: 0 run: 1 sbin: 1 srv: 1 sys: 1 tmp: 1 usr: 1 var: 1 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73488&edit=1

« previous php.bugs (#205287) next »