note 94149 added to function.glob
| From: | TommyO at osu1 dot php dot net | Date: | Mon, 19 Oct 2009 19:14:09 +0000 |
| Subject: | note 94149 added to function.glob | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161879@lists.php.net to get a copy of this message | ||
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) {
...
}
?>
----
Server IP: 192.41.40.227
Probable Submitter: 69.86.124.171
----
Manual Page -- http://www.php.net/manual/en/function.glob.php
Edit -- https://master.php.net/note/edit/94149
Del: integrated -- https://master.php.net/note/delete/94149/integrated
Del: useless -- https://master.php.net/note/delete/94149/useless
Del: bad code -- https://master.php.net/note/delete/94149/bad+code
Del: spam -- https://master.php.net/note/delete/94149/spam
Del: non-english -- https://master.php.net/note/delete/94149/non-english
Del: in docs -- https://master.php.net/note/delete/94149/in+docs
Del: other reasons-- https://master.php.net/note/delete/94149
Reject -- https://master.php.net/note/reject/94149
Search -- https://master.php.net/manage/user-notes.php