* Thus wrote Aaron Wormus:
> 
> foreach (new DirectoryIterator('.') as $file) {
>     echo "<pre>";
>     var_dump($file);
> 
>     if (preg_match("/xxx/", $file)){
>         // Why is this breaking $file??
>       //    without even a warning
>     }
> 
>     var_dump($file);
>     echo "</pre>";
> }


This probably needs some attention, here are some related issues that
I've came accross trying to find out why the above was happening:


Test 1: ($file holds last type conversion)
<?php
foreach (new DirectoryIterator('.') as $file) {
    echo "\n--\n";
    var_dump($file);
    preg_match("/xxx/", $file);
    var_dump($file);
    echo "\n--";
}

Output:
Object(DirectoryIterator)#1 (0) {
}
string(1) "."
--
--
string(1) "."
string(1) "."
--
...


Test 2: (working example)
----------
<?php
$d = new DirectoryIterator('.');
foreach ($d as &$file) {
    echo "\n--\n";
    var_dump($file);
    preg_match("/xxx/", $file);
    var_dump($file);
    echo "\n--";
}

Output:
--
object(DirectoryIterator)#1 (0) {
}
object(DirectoryIterator)#1 (0) {
}
--
--
object(DirectoryIterator)#1 (0) {
}
object(DirectoryIterator)#1 (0) {
}
--

...

Test 3: (completly fails)
----------
<?php
foreach (new DirectoryIterator('.') as &$file) {
    echo "\n--\n";
    var_dump($file);
    preg_match("/xxx/", $file);
    var_dump($file);
    echo "\n--\n";
}

Output:
PHP Parse error:  syntax error, unexpected T_STRING in test.php on line 2


This appears to be a definate bug somewhere and I cant spot it atm.


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to