ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-dev
php-dev
#44964 [Opn->Asn]: DirectoryIterator assignment within foreach()
by colder other posts by this author
May 11 2008 5:13AM messages near this date
#44964 [Asn->Bgs]: DirectoryIterator assignment within foreach() | #44965 [NEW]: Zend affects on arrays
ID:               44964
 Updated by:       colder@[...].net
 Reported By:      phpbugs at rjharrison dot org
-Status:           Open
+Status:           Assigned
 Bug Type:         SPL related
 Operating System: Linux (fedora core 6  i think)
 PHP Version:      5.2.6
-Assigned To:      
+Assigned To:      colder


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

[2008-05-10 19:25:02] phpbugs at rjharrison dot org

Description:
------------
When looping over a $directorIterator using FOREACH something goes
wrong when assigning the "as" variable to an array.




Reproduce code:
---------------
$filePath   = 'PUT YOUR TEST PATH HERE';
$dir        = new DirectoryIterator($filePath);
$files      = array();

foreach ($dir as $file){
    $files[] = $file;
    echo $file-> getFilename(), " / ", $file->getSize(), " bytes\n";
}

echo "\nSecond loop:-\n";

foreach ($files as $file2){
    echo $file2-> getFilename(), " / ", $file2->getSize(), " bytes\n";
}


Expected result:
----------------
(Depends on the files but assuming a single file in the directory)

test.php / 18 bytes
. / 4096 bytes
.. / 4096 bytes

Second run:-
test.php / 18 bytes
. / 4096 bytes
.. / 4096 bytes

Actual result:
--------------
test.php / 18 bytes
. / 4096 bytes
.. / 4096 bytes

Second run:-
 / 4096 bytes
 / 4096 bytes
 / 4096 bytes


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


-- 
Edit this bug report at http://bugs.php.net/?id=44964&edit=1
Thread:
Phpbugs At Rjharrison Dot Org
Phpbugs At Rjharrison Dot Org
colder
colder

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved