Closed (fixed)
Project:
Variable
Version:
7.x-1.1
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 Dec 2011 at 15:27 UTC
Updated:
20 Feb 2012 at 15:30 UTC
Jump to comment: Most recent file
variable_realm() function returns value by reference and uses static variable $variable_realm that in turn is a reference to drupal_static storage.
Due to PHP behavior http://www.php.net/manual/en/language.variables.scope.php#language.varia... you cannot have a static reference variable:
A similar behaviour applies to the static statement. References are not stored statically:
Also, take a look at Drupal core examples.
As a result switch variables realms is not working properly $variable_realm['default']['config'] is being overridden by current $GLOBALS['conf'] on each call.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | variable-wrong-drupal-static-utilization-1371906-3.patch | 1.15 KB | taran2l |
| #1 | wrong-drupal-static-utilization-1371906-1.patch | 875 bytes | taran2l |
Comments
Comment #1
taran2lPatch attached.
Please review.
Comment #2
jose reyero commentedThat drupal_static() usage should be ok and it is documented, see 'advanced drupal_static() pattern', http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/drupal...
However you may be right about the static reference to a global variable, though I don't think your patch will fix that issue as it just changes how the variable is initialized but not the assignmet of the global variable.
We'd need a more specific (may be code) example of this issue to see when this is failing.
Comment #3
taran2lAdvanced drupal_static() pattern requires use of an array() wrapper (and this moment is described in the docs).
My previous patch actually fixes the problem, but switches drupal_static() storage to use simple pattern.
Attached new version with correct use of advanced drupal_static() pattern. Please review.
Couple more details. Problem is in these lines:
The new patch uses work around from http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/drupal...
Comment #4
jose reyero commentedOk, got it. Committed, thanks.
Btw, fixed variable_store() the same way.