note 49308 added to function.glob
| From: | php-general at lists dot php dot net | Date: | Sun, 23 Jan 2005 21:54:40 +0000 |
| Subject: | note 49308 added to function.glob | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83830@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";
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.glob.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49308
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49308&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49308&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49308&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49308&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49308&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49308&report=yes
Search -- http://master.php.net/manage/user-notes.php