Posted by bmihelac on May 13, 2008 at 4:45am
Jump to:
| Project: | Drupal core |
| Version: | 5.7 |
| Component: | locale.module |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (won't fix) |
Issue Summary
Static variables are used to cache $all and $enabled languages with unset() function to reset cache. unset() function just unsets variable inside function and PHP reset its value next time the function is called. This way after reset return value is same as before reset.
Here is example how static caching works with unset():
<?php
function locale_supported_languages($reset = FALSE, $val = array()) {
static $all = NULL;
if ($reset) {
// If a static variable is unset() inside of a function, unset() destroys the variable only in the context of the rest of a function. Following calls will restore the previous value of a variable.
// unset($all);
$all = NULL;
}
if (is_null($all)) {
$all = array();
foreach ($val as $key => $value) {
$all[$key] = $value;
}
}
return $all;
}
echo "\narray should have 'cached' element (PASS):";
print_r(locale_supported_languages(FALSE, array("first" => "cached")));
echo "\narray should have 'new' element (PASS):";
print_r(locale_supported_languages(TRUE, array("first" => "new")));
echo "\narray should have 'new' element but have 'cached' (FAILS):";
print_r(locale_supported_languages(FALSE));
?>Solution is easy, just set variable to NULL instead unsetting it.
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| locale_supported_languages_static_cache_bug.patch | 668 bytes | Ignored: Check issue status. | None | None |
Comments
#1
Drupal 5 is not supported anymore. Drupal 6 and 7 does not have this problem, eg. http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/langua...