Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.886 diff -u -p -r1.886 common.inc --- includes/common.inc 26 Apr 2009 16:09:57 -0000 1.886 +++ includes/common.inc 26 Apr 2009 18:45:36 -0000 @@ -49,7 +49,7 @@ define('JS_THEME', 100); * Content to be set. */ function drupal_set_content($region = NULL, $data = NULL) { - static $content = array(); + $content = &drupal_static(__FUNCTION__, array()); if (!is_null($region) && !is_null($data)) { $content[$region][] = $data; @@ -91,7 +91,7 @@ function drupal_get_content($region = NU * the current page. */ function drupal_set_breadcrumb($breadcrumb = NULL) { - static $stored_breadcrumb; + $stored_breadcrumb = &drupal_static(__FUNCTION__); if (!is_null($breadcrumb)) { $stored_breadcrumb = $breadcrumb; @@ -131,7 +131,7 @@ function drupal_get_rdf_namespaces() { * This function can be called as long the headers aren't sent. */ function drupal_add_html_head($data = NULL) { - static $stored_head = ''; + $stored_head = &drupal_static(__FUNCTION__, ''); if (!is_null($data)) { $stored_head .= $data . "\n"; @@ -165,7 +165,7 @@ function drupal_clear_path_cache() { * The title of the feed. */ function drupal_add_feed($url = NULL, $title = '') { - static $stored_feed_links = array(); + $stored_feed_links = &drupal_static(__FUNCTION__, array()); if (!is_null($url) && !isset($stored_feed_links[$url])) { $stored_feed_links[$url] = theme('feed_icon', $url, $title); @@ -767,6 +767,8 @@ function _drupal_log_error($error, $fata // When running inside the testing framework, we relay the errors // to the tested site by the way of HTTP headers. if (preg_match("/^simpletest\d+/", $_SERVER['HTTP_USER_AGENT']) && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) { + // $number does not use drupal_static as it should not be reset + // as it uniquely identifies each PHP error. static $number = 0; $assertion = array( $error['%message'], @@ -877,7 +879,7 @@ function _fix_gpc_magic_files(&$item, $k * Fix double-escaping problems caused by "magic quotes" in some PHP installations. */ function fix_gpc_magic() { - static $fixed = FALSE; + $fixed = &drupal_static(__FUNCTION__, FALSE); if (!$fixed && ini_get('magic_quotes_gpc')) { array_walk($_GET, '_fix_gpc_magic'); array_walk($_POST, '_fix_gpc_magic'); @@ -1083,7 +1085,7 @@ function fix_gpc_magic() { */ function t($string, $args = array(), $langcode = NULL) { global $language; - static $custom_strings; + $custom_strings = &drupal_static(__FUNCTION__); if (!isset($langcode)) { $langcode = isset($language->language) ? $language->language : 'en'; @@ -1522,7 +1524,7 @@ function format_interval($timestamp, $gr * A translated date string in the requested format. */ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) { - static $timezones = array(); + $timezones = &drupal_static(__FUNCTION__, array()); if (!isset($timezone)) { global $user; if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) { @@ -1675,7 +1677,7 @@ function url($path = NULL, array $option } global $base_url; - static $script; + $script = &drupal_static(__FUNCTION__); if (!isset($script)) { // On some web servers, such as IIS, we can't omit "index.php". So, we @@ -2036,7 +2038,7 @@ function drupal_add_link($attributes) { * An array of queued cascading stylesheets. */ function drupal_add_css($data = NULL, $options = NULL) { - static $css = array(); + $css = &drupal_static(__FUNCTION__, array()); global $language; // Construct the options, taking the defaults into consideration. @@ -2235,7 +2237,7 @@ function drupal_build_css_cache($types, * This function will prefix all paths within a CSS file. */ function _drupal_build_css_path($matches, $base = NULL) { - static $_base; + $_base = &drupal_static(__FUNCTION__); // Store base path for preg_replace_callback. if (isset($base)) { $_base = $base; @@ -2270,7 +2272,8 @@ function _drupal_build_css_path($matches * Contents of the stylesheet, including any resolved @import commands. */ function drupal_load_stylesheet($file, $optimize = NULL) { - static $_optimize; + // $_optimize does not use drupal_static as it is set by $optimize. + $_optimize = &drupal_static(__FUNCTION__); // Store optimization parameter for preg_replace_callback with nested @import loops. if (isset($optimize)) { $_optimize = $optimize; @@ -2445,7 +2448,7 @@ function drupal_clear_css_cache() { * @see drupal_get_js() */ function drupal_add_js($data = NULL, $options = NULL) { - static $javascript = array(); + $javascript = &drupal_static(__FUNCTION__, array()); // Construct the options, taking the defaults into consideration. if (isset($options)) { @@ -2458,11 +2461,6 @@ function drupal_add_js($data = NULL, $op } $options += drupal_js_defaults($data); - if ($options['type'] == 'reset') { - // Request made to reset the JavaScript added so far - return $javascript = array(); - } - // Preprocess can only be set if caching is enabled. $options['preprocess'] = $options['cache'] ? $options['preprocess'] : FALSE; @@ -2759,7 +2757,7 @@ function drupal_get_js($scope = 'header' * @see theme_menu_overview_form() */ function drupal_add_tabledrag($table_id, $action, $relationship, $group, $subgroup = NULL, $source = NULL, $hidden = TRUE, $limit = 0) { - static $js_added = FALSE; + $js_added = &drupal_static(__FUNCTION__, FALSE); if (!$js_added) { // Add the table drag JavaScript to the page before the module JavaScript // to ensure that table drag behaviors are registered before any module @@ -2892,6 +2890,7 @@ function drupal_urlencode($text) { * The number of characters (bytes) to return in the string. */ function drupal_random_bytes($count) { + // $random_state does not use drupal_static as it stores random bytes. static $random_state; // We initialize with the somewhat random PHP process ID on the first call. if (empty($random_state)) { @@ -2991,7 +2990,7 @@ function xmlrpc($url) { } function _drupal_bootstrap_full() { - static $called; + $called = &drupal_static(__FUNCTION__); if ($called) { return; @@ -3481,10 +3480,10 @@ function element_sort($a, $b) { /** * Retrieve the default properties for the defined element type. */ -function element_info($type, $refresh = NULL) { - static $cache; +function element_info($type) { + $cache = &drupal_static(__FUNCTION__); - if (!isset($cache) || $refresh) { + if (!isset($cache)) { $basic_defaults = element_basic_defaults(); $cache = array(); foreach (module_implements('elements') as $module) { Index: modules/simpletest/tests/common.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v retrieving revision 1.34 diff -u -p -r1.34 common.test --- modules/simpletest/tests/common.test 25 Apr 2009 13:56:06 -0000 1.34 +++ modules/simpletest/tests/common.test 26 Apr 2009 18:45:36 -0000 @@ -433,7 +433,7 @@ class JavaScriptTestCase extends DrupalW variable_set('preprocess_js', 0); // Reset drupal_add_js() before each test. - drupal_add_js(NULL, 'reset'); + drupal_static_reset('drupal_add_js'); } function tearDown() { @@ -485,7 +485,7 @@ class JavaScriptTestCase extends DrupalW */ function testReset() { drupal_add_js('misc/collapse.js'); - drupal_add_js(NULL, 'reset'); + drupal_static_reset('drupal_add_js'); $this->assertEqual(array(), drupal_add_js(), t('Resetting the JavaScript correctly empties the cache.')); }