Skip to content

Commit 69550c5

Browse files
committed
Fix caching of MIME config
* in get_mimes(): was missing isset() test * in Email->_mimes_types(): static cache of reference was noneffective refs 6ef498b
1 parent 5b9251f commit 69550c5

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

system/core/Common.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,22 @@ function config_item($item)
304304
*/
305305
function &get_mimes()
306306
{
307-
static $_mimes = array();
307+
static $_mimes;
308308

309-
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
309+
if (empty($_mimes))
310310
{
311-
$_mimes = include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
312-
}
313-
elseif (file_exists(APPPATH.'config/mimes.php'))
314-
{
315-
$_mimes = include(APPPATH.'config/mimes.php');
311+
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
312+
{
313+
$_mimes = include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
314+
}
315+
elseif (file_exists(APPPATH.'config/mimes.php'))
316+
{
317+
$_mimes = include(APPPATH.'config/mimes.php');
318+
}
319+
else
320+
{
321+
$_mimes = array();
322+
}
316323
}
317324

318325
return $_mimes;

system/libraries/Email.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,15 +2234,18 @@ protected function _set_error_message($msg, $val = '')
22342234
*/
22352235
protected function _mime_types($ext = '')
22362236
{
2237-
static $mimes;
2237+
static $_mimes;
22382238

22392239
$ext = strtolower($ext);
22402240

2241-
if ( ! is_array($mimes))
2241+
if (empty($_mimes))
22422242
{
2243-
$mimes =& get_mimes();
2243+
// references cannot be directly assigned to static variables, so we use an array
2244+
$_mimes[0] =& get_mimes();
22442245
}
22452246

2247+
$mimes =& $_mimes[0];
2248+
22462249
if (isset($mimes[$ext]))
22472250
{
22482251
return is_array($mimes[$ext])

0 commit comments

Comments
 (0)