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().


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.