note 49308 modified in function.glob by felipe
| From: | felipe@php.net | Date: | Mon, 26 Nov 2007 10:06:04 +0000 |
| Subject: | note 49308 modified in function.glob by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-132569@lists.php.net to get a copy of this message | ||
The example on this page will generate a warning if the glob function does not find any filenames
that match the pattern.
The glob function result will only be an array if it finds some files and the foreach statement
requires its argument to be an array.
By checking for the possibility that the result of the glob function may not be an array you can
eliminate the warning.
Here's a better example:
<?php
$matches = glob("*.txt");
if ( is_array ( $matches ) ) {
foreach ( $matches as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}
}
?>
--was--
The example on this page will generate a warning if the glob function does not find any filenames
that match the pattern.
The glob function result will only be an array if it finds some files and the foreach statement
requires its argument to be an array.
By checking for the possibility that the result of the glob function may not be an array you can
eliminate the warning.
Here's a better example:
<?php
$matches = glob("*.txt");
if ( is_array ( $matches ) ) {
foreach ( $matches as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}
}
?>
http://php.net/manual/en/function.glob.php