note 94149 deleted from function.glob by danbrown
| From: | danbrown@php.net | Date: | Mon, 19 Oct 2009 22:04:22 +0000 |
| Subject: | note 94149 deleted from function.glob by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161883@lists.php.net to get a copy of this message | ||
Note Submitter: TommyO
----
re: tailinchu[at]gmail[dot]com
That is a rather expensive method, as glob() gets called twice on success, only to save a couple of
lines of code.
<?php
if (!$files = glob($dir)) {
$files = array();
}
?>
Is still a little too lazy for my tastes, but at least it's cheaper.
A lazier but cleaner method would be to cast to array when using it as an array;
<?php
$files = glob($dir);
foreach ((array)$files as $file) {
...
}
?>