From 447647910e0bb6e505c025d1da22d44a69de6eb1 Mon Sep 17 00:00:00 2001 From: Lawrence Brown Date: Sat, 3 Jan 2015 16:29:17 +0000 Subject: [PATCH] loop over directories the "correct" way see http://php.net/manual/en/function.readdir.php - specifically: /* This is the correct way to loop over the directory. */ while (false !== ($entry = readdir($handle))) { echo "$entry\n"; } /* This is the WRONG way to loop over the directory. */ while ($entry = readdir($handle)) { echo "$entry\n"; } --- lib/class/art.class.php | 2 +- lib/class/catalog.class.php | 2 +- lib/class/localplay.class.php | 2 +- lib/class/plugin.class.php | 2 +- lib/general.lib.php | 2 +- modules/Auth/OpenID/FileStore.php | 2 +- modules/captcha/captcha.php | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/class/art.class.php b/lib/class/art.class.php index 143b023bb0..56237554e4 100644 --- a/lib/class/art.class.php +++ b/lib/class/art.class.php @@ -1031,7 +1031,7 @@ public function gather_folder($limit = 5) $processed[$dir] = true; // Recurse through this dir and create the files array - while ($file = readdir($handle)) { + while (false !== ($file = readdir($handle))) { $extension = pathinfo($file); $extension = $extension['extension']; diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 4693225d00..ec828412bd 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -293,7 +293,7 @@ public static function get_catalog_types() $results = array(); - while ($file = readdir($handle)) { + while (false !== ($file = readdir($handle))) { if (substr($file, -11, 11) != 'catalog.php') { continue; } diff --git a/lib/class/localplay.class.php b/lib/class/localplay.class.php index 4a53088045..c92de5ab96 100644 --- a/lib/class/localplay.class.php +++ b/lib/class/localplay.class.php @@ -150,7 +150,7 @@ public static function get_controllers() $results = array(); - while ($file = readdir($handle)) { + while (false !== ($file = readdir($handle))) { if (substr($file,-14,14) != 'controller.php') { continue; } diff --git a/lib/class/plugin.class.php b/lib/class/plugin.class.php index 25062e9df3..409d06ef22 100644 --- a/lib/class/plugin.class.php +++ b/lib/class/plugin.class.php @@ -88,7 +88,7 @@ public static function get_plugins($type='') } // Recurse the directory - while ($file = readdir($handle)) { + while (false !== ($file = readdir($handle))) { // Ignore non-plugin files if (substr($file,-10,10) != 'plugin.php') { continue; } if (is_dir($file)) { continue; } diff --git a/lib/general.lib.php b/lib/general.lib.php index 4aca643d6e..a28101ef65 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -166,7 +166,7 @@ function get_languages() /* Prepend English */ $results['en_US'] = 'English (US)'; - while ($file = readdir($handle)) { + while (false !== ($file = readdir($handle))) { $full_file = AmpConfig::get('prefix') . '/locale/' . $file; diff --git a/modules/Auth/OpenID/FileStore.php b/modules/Auth/OpenID/FileStore.php index 7eec791d24..d74f83dcb4 100644 --- a/modules/Auth/OpenID/FileStore.php +++ b/modules/Auth/OpenID/FileStore.php @@ -482,7 +482,7 @@ function _rmtree($dir) } if ($handle = opendir($dir)) { - while ($item = readdir($handle)) { + while (false !== ($item = readdir($handle))) { if (!in_array($item, array('.', '..'))) { if (is_dir($dir . $item)) { diff --git a/modules/captcha/captcha.php b/modules/captcha/captcha.php index 5c8ad8168d..336aa87c51 100644 --- a/modules/captcha/captcha.php +++ b/modules/captcha/captcha.php @@ -394,7 +394,7 @@ function straighten_temp_dir() { // clean up old files if ((rand(0,100) <= 5) && ($dh = opendir($dir))) { $t_kill = time() - CAPTCHA_TIMEOUT * 1.2; - while($fn = readdir($dh)) if ($fn[0] != ".") { + while(false !== ($fn = readdir($dh))) if ($fn[0] != ".") { if (filemtime("$dir/$fn") < $t_kill) { @unlink("$dir/$fn"); } @@ -1258,4 +1258,4 @@ function canonical_path($url) { -?> \ No newline at end of file +?>