Problem/Motivation
We want to deprecate drupal_static() and drupal_static_reset(): #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset()
However, for backwards compatibility, we have to turn drupal_static_reset() into a special case that does not call @trigger_error().
This is also used in some cases where it can be called many times in a request, we should only trigger once.
Proposed resolution
Formally deprecate drupal_static_reset() and drupal_static().
Add a special name for skipping deprecations.
Add a drupal memory cache to call only once per request
Remaining tasks
Close and apply credit here #2260187: [PP-1] Deprecate drupal_static() and drupal_static_reset()
Review
User interface changes
N/A
API changes
Data model changes
N/A
Release notes snippet
Issue fork drupal-3037054
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
andypostI think it needs better CR about how to prevent using static cos it brings state to services
Comment #3
claudiu.cristea\Drupal\migrate\MigrateExecutable::attemptMemoryReclaim()needs this call too.Comment #9
berdir> \Drupal\migrate\MigrateExecutable::attemptMemoryReclaim() needs this call too.
I'd argue it's fine to drop that without replacement as the chances that there's any memory worth reclaiming is lower and lower.
I'd argue we could just close this and use the approach that you proposed in the main issue for the few calls like this that must still call it.
Comment #15
nicxvan commentedI think this is actually not as hard as it initially seems.
Once we deprecate all other instances in core we introduce a special key
clear_all.Then we do this:
Then the two remaining calls we call with
clear_allas the argument and won't trigger the deprecation and all other calls will.Comment #16
nicxvan commentedComment #18
nicxvan commentedCurious if we think we can get this in for 11.5
Comment #19
daffie commentedComment #20
daffie commentedAll code changes look good to me.
For me it is RTBC.
Comment #21
catchI think using a memory cache for the handful of stragglers is a good approach so we can start notifying contrib of drupal_static()'s impending demise earlier. Good to be able to commit this one seven years (!) after it was opened.
Committed/pushed to main, thanks!
Will need a backport MR for 11.x
Comment #23
nicxvan commentedOk this is ready now.
There were four additional uses in 11.x I had to mark as ignore.
2 in history which was removed from core.
2 in common for functions that were deprecated and removed already.
Failure seems random it's:
EntityReferenceWidgetTestComment #26
catchCherry-picked to 12.0.x because the branch was opened in between the main commit and the push actually succeeding, and backported to 11.x, thanks!
Comment #29
claudiu.cristeaWow!
Comment #30
feuerwagenThanks for your work especially @claudiu.cristea - I've been watching from the sidelines how you chipped away at this for (8+!) years. Love to see that it finally reached its goal.