Problem/Motivation

In #2260187: [PP-1] Deprecate drupal_static() and drupal_static_reset() we'll deprecate the drupal_static() & drupal_static_reset() procedural functions. However, in order to do so, we have to remove first all usages from Drupal core.

Proposed resolution

We cannot do all the removals in one step. Each usage it's an issue itself. So, this issues is a META to track the progress:

Child issues:

Done:

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Original report

from comment #19 of #1567428: Active trail tests, in order to handle static variables in Drupal 8 we should convert every use of statics to instead be protected properties of proper objects. The result of this effort will be that we properly register objects into the Dependency Injection Container and perhaps do away with drupal_static() and drupal_static_reset().

Comments

cosmicdreams’s picture

Issue tags: +MN code sprint
Crell’s picture

This isn't a task unto itself per se, I think, but rather a side-effect of other work. Eg, the menu system needs to be turned into a proper set of objects (after routing it ripped out), and the statics eliminated as part of that. Simply creating objects somewhere that hold statics instead of them being inside functions buys us nothing.

sun’s picture

Title: Convert all statics to Object Properties » [meta] Remove all drupal_static()s + drupal_static() itself
Issue summary: View changes
Issue tags: -MN code sprint +@deprecated, +DIE

HEAD has 93 calls to drupal_static()

Most of them in legacy procedural code that is actively being converted into service classes right now. In essence, those calls should "magically vanish" ;-)

However, for some strange reason, some drupal_static()s were taken over as-is into object-oriented code that is clean otherwise. For example, Drupal\Core\Cache\DatabaseBackend still maintains the state of cache tags via drupal_static().

In any case, these drupal_static()s (1) prevent us from properly using and leveraging the kernel and (2) harm tests.

tim.plunkett’s picture

Priority: Normal » Major
Issue tags: +beta target

Spoke with @alexpott in IRC, he said this did not qualify for a beta or release blocker, but agreed it should be a beta target.

catch’s picture

The database backend should get fixed by #918538: Decouple cache tags from cache bins (it should have been converted to a static property of the class initially, but better to fix it properly in that issue).

Berdir’s picture

static does not work because static survives test tearDown(), I tried that :)

sidharrell’s picture

Issue summary: View changes

changed issue summary to better reflect how to do the replacement.

andypost’s picture

@alexpott in IRC, he said this did not qualify for a beta or release blocker, but agreed it should be a beta target.

So how this issue fits into 8.0.x?

catch’s picture

Priority: Major » Normal

There's not really anything that can be done in itself here. There are 68 references to drupal_static() left in the code base. This is compared to 191 in Drupal 7.

During the 8.x cycle, we'll be able to move more code to classes/services, which will mean less drupal_static() calls, leaving procedural wrappers in for bc.

Then once core isn't using it, drupal_static() can be deprecated, then removed for 9.0.x.

Crell’s picture

Would it make sense to mark it deprecated now, slated for 9.x removal, so that contrib authors know to stop using it?

catch’s picture

No I think we need to only mark things @deprecated when there is active work to replace them with a definite alternative. A lot of things got marked deprecated in the 8.x cycle without a viable replacement, most infamously url() and l(), and that led to nasty surprises later on. So when there are no uses of drupal_static() in core, or if all the usages are only in functions that are marked @deprecated themselves, let's mark it, but not before.

almaudoh’s picture

Version: 8.0.x-dev » 8.2.x-dev
xjm’s picture

Issue tags: -beta target

This issue was marked as a beta target for the 8.0.x beta, but is not applicable as an 8.1.x beta target, so untagging.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Title: [meta] Remove all drupal_static()s + drupal_static() itself » [META] Remove all usages of drupal_static() & drupal_static_reset()
Issue summary: View changes
Issue tags: -Dependency Injection (DI), -DIE
Parent issue: » #2260187: [PP-1] Deprecate drupal_static() and drupal_static_reset()

Trying to revive this META. Fixing title, IS. Will open child issues.

claudiu.cristea’s picture

Issue summary: View changes

Adding new child issues.

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
Mile23’s picture

andypost’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
Mile23’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

volkswagenchick’s picture

Issue tags: +midcamp2019

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes

The inventory is over. There are still few cases that are falling in the scope of #3037054: Deprecate drupal_static_reset() without @trigger_error().

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes

Updating the list by moving the finished issues to a new section.

claudiu.cristea’s picture

We should wait with deprecations until we have a decision in #3047289: Standardize how we implement in-memory caches.

markdorison’s picture

Issue tags: +Seattle2019
claudiu.cristea’s picture

Issue summary: View changes

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

daffie’s picture

daffie’s picture

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

shaktik’s picture

Assigned: Unassigned » shaktik
shaktik’s picture

Assigned: shaktik » Unassigned

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes

Updated the list.

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes

Reverting wrong IS change.

claudiu.cristea’s picture

claudiu.cristea’s picture

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

samuel.mortenson’s picture

I wanted to note that from reviewing a few related core/contrib isues like #2488458: remove calls to drupal_static(), I think we may be regressing on functionality that drupal_static() gave us.

I maintain Tome, a static site generator for Drupal, and one of the performance enhancements in that module is to perform multiple Drupal requests in one bootstrap (PHP process). Between requests, Tome performs a variety of operations to try to clear things in memory that were related to a previous request, and as a part of that calls drupal_static_reset(). See https://git.drupalcode.org/project/tome/-/blob/8.x-1.x/modules/tome_stat... for the full gory details. A goal of mine in the future is to contribute core patches for everything there that doesn't already use drupal_static() to use MemoryCache . For example I just found that \Drupal\views\Plugin\views\row\RssFields::render uses "static" where it should use drupal_static() or MemoryCache.

If core or contrib migrates usages of drupal_static() to storing things in protected variables or going back to using "static", it will make things a lot harder for me. Can we make sure that the guidance is to move to MemoryCache, not to come up with custom "cache in memory" implementations?

catch’s picture

That's being discussed in #3047289: Standardize how we implement in-memory caches, we might even want to postpone this on that issue?

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Category: Task » Plan

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jweowu’s picture

I agree with waiting until there is a standard replacement for drupal_static() which provides equivalent functionality and can be easily employed to replace the original API calls.

I'm really startled to observe that a lot of commits have been made replacing drupal_static() with plain PHP static! To my mind that is counter-productive and achieves nothing more than the removal of useful functionality.

I think those commits ought to be revisited once a new API is available so that they can be refitted with the new standard.

jweowu’s picture

Status: Active » Postponed

Per #86, setting this to Postponed pending #3047289: Standardize how we implement in-memory caches.

(And once that is resolved, the previous changes made for this issue ought to be reviewed.)