Community Documentation

globals.php

  1. drupal
    1. 6 globals.php
    2. 7 globals.php
    3. 8 globals.php

These are the global variables that Drupal uses.

Globals

NameDescription
$base_pathThe base path of the Drupal installation.
$base_rootThe root URL of the host, excluding the path.
$base_theme_infoAn array of objects that represent the base theme.
$base_urlThe base URL of the Drupal installation.
$channelAn associative array containing title, link, description and other keys.
$confArray of persistent variables stored in 'variable' table.
$cookie_domainThe domain to be used for session cookies.
$databasesArray of database connections.
$elementStructured array describing the data to be rendered.
$forum_topic_list_headerAn array of forum topic header information.
$imageCurrent image tag used by aggregator parsing.
$installed_profileThe name of the profile that has just been installed.
$itemGeneral string or array.
$itemsArray of items used by aggregator.
$languageAn object containing the information for the active interface language.
$language_contentAn object containing the information for the active content language.
$language_urlAn object containing the information for the active URL language.
$menu_adminBoolean indicating that a menu administrator is running a menu access check.
$multibyteThe current multibyte mode.
$pager_limitsArray of the number of items per page for each pager.
$pager_page_arrayArray of current page numbers for each pager.
$pager_totalArray of the total number of pages for each pager.
$pager_total_itemsArray of the total number of items for each pager.
$tagActive tag name.
$themeName of the active theme.
$theme_engineThe theme engine related to the active theme.
$theme_infoActive theme object.
$theme_keyName of the active theme.
$theme_pathThe path to the active theme.
$timersTimers that have been created by timer_start().
$update_free_accessAllows the update.php script to be run when not logged in as administrator.
$userAn object representing the currently logged-in user.
View source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php

/**
 * @file
 * These are the global variables that Drupal uses.
 */

/**
 * Timers that have been created by timer_start().
 *
 * @see timer_start()
 * @see timer_read()
 * @see timer_stop()
 */
global $timers;

/**
 * The base URL of the Drupal installation.
 *
 * @see drupal_settings_initialize()
 */
global $base_url;

/**
 * The base path of the Drupal installation.
 *
 * This will at least default to '/'.
 *
 * @see drupal_settings_initialize()
 */
global $base_path;

/**
 * The root URL of the host, excluding the path.
 *
 * @see drupal_settings_initialize()
 */
global $base_root;

/**
 * Array of database connections.
 *
 * @see default.settings.php
 */
global $databases;

/**
 * The domain to be used for session cookies.
 *
 * Cookie domains must contain at least one dot other than the first (RFC 2109).
 * For hosts such as 'localhost' or an IP Addresses the cookie domain will not
 * be set.
 *
 * @see default.settings.php
 */
global $cookie_domain;

/**
 * Array of persistent variables stored in 'variable' table.
 *
 * @see variable_get()
 * @see variable_set()
 * @see variable_del()
 */
global $conf;

/**
 * The name of the profile that has just been installed.
 */
global $installed_profile;

/**
 * Allows the update.php script to be run when not logged in as administrator.
 *
 * @see default.settings.php
 */
global $update_free_access;

/**
 * An object representing the currently logged-in user.
 *
 * Contains preferences and other user information.
 */
global $user;

/**
 * An object containing the information for the active interface language.
 *
 * It represents the language the user interface textual elements such as
 * titles, labels or messages, are to be displayed in.
 *
 * Example values:
 *  - 'language' => 'en',
 *  - 'name' => 'English',
 *  - 'native' => 'English',
 *  - 'direction' => 0,
 *  - 'enabled' => 1,
 *  - 'plurals' => 0,
 *  - 'formula' => '',
 *  - 'domain' => '',
 *  - 'prefix' => '',
 *  - 'weight' => 0,
 *  - 'javascript' => ''
 *
 * @see LANGUAGE_TYPE_INTERFACE
 * @see drupal_language_initialize()
 */
global $language;

/**
 * An object containing the information for the active content language.
 *
 * It is used by the Field API as a default value when no language is specified
 * to select the field translation to be displayed.
 *
 * @see LANGUAGE_TYPE_CONTENT
 * @see drupal_language_initialize()
 */
global $language_content;

/**
 * An object containing the information for the active URL language.
 *
 * It is used as a default value by URL-related functions such as l() when no
 * language is explicitly specified.
 *
 * @see LANGUAGE_TYPE_URL
 * @see drupal_language_initialize()
 */
global $language_url;

/**
 * Array of current page numbers for each pager.
 *
 * @see PagerDefault
 */
global $pager_page_array;

/**
 * Array of the total number of pages for each pager.
 *
 * The array index is the pager element index (0 by default).
 *
 * @see PagerDefault
 */
global $pager_total;

/**
 * Array of the total number of items for each pager.
 *
 * The array index is the pager element index (0 by default).
 *
 * @see PagerDefault
 */
global $pager_total_items;

/**
 * Array of the number of items per page for each pager.
 *
 * The array index is the pager element index (0 by default).
 *
 * @see PagerDefault
 */
global $pager_limits;

/**
 * Name of the active theme.
 */
global $theme;

/**
 * Name of the active theme.
 *
 * @see init_theme()
 */
global $theme_key;

/**
 * Active theme object.
 *
 * @see _drupal_theme_initialize()
 */
global $theme_info;

/**
 * An array of objects that represent the base theme.
 *
 * @see _drupal_theme_initialize()
 */
global $base_theme_info;

/**
 * The theme engine related to the active theme.
 */
global $theme_engine;

/**
 * The path to the active theme.
 */
global $theme_path;

/**
 * The current multibyte mode.
 *
 * Possible values: UNICODE_ERROR, UNICODE_SINGLEBYTE, UNICODE_MULTIBYTE.
 */
global $multibyte;

/**
 * General string or array.
 *
 * @see aggregator_element_start()
 */
global $item;

/**
 * Structured array describing the data to be rendered.
 *
 * @see aggregator_element_start()
 */
global $element;

/**
 * Active tag name.
 *
 * @see aggregator_element_start()
 */
global $tag;

/**
 * Array of items used by aggregator.
 *
 * @see aggregator_element_start()
 */
global $items;

/**
 * An associative array containing title, link, description and other keys.
 *
 * The link should be an absolute URL.
 *
 * @see aggregator_element_start()
 */
global $channel;

/**
 * Current image tag used by aggregator parsing.
 *
 * @see aggregator_aggregator_parse()
 */
global $image;

/**
 * An array of forum topic header information.
 */
global $forum_topic_list_header;

/**
 * Boolean indicating that a menu administrator is running a menu access check.
 */
global $menu_admin;

Comments

If you are searching for the

If you are searching for the root path of your drupal installation as a filesystem path, you will not find the variable here.

Instead just use:

DRUPAL_ROOT

I searched for quite some time for it and had expected that to find it here, so I am adding this as a comment for others to find.

A $debug variable would be nice

It would be nice to have a $debug variable for modules (and core) to add "verbose"-type information whenever they're experiencing something that may contribute to errors. When site builders are experiencing errors, they could first raise an internal debug verbosity level, and then go look at this array. Module developers would have a place to put such information - including warnings of suspicious or unexpected input values - without having to resort to filling up the error log with details that could be trivial compared to other, more important information.

It could be an array something like this:

$debug[0] = array(
'time' => time(),
'importance' => int 1-10,
'module name' => ...,
'message' => 'Got a string here when expecting an array - outputting the string instead of #markup - possible conflict with the xyz_module',
'tags' => pipe-delineated list of tags
);

A firebug-like client could sort these according to runtime, importance, module, tags etc., or you could just put print_r($debug) at the bottom of your theme.

No database table is needed - simply a convention to follow for module developers.

Also: In cases where you are taking over a Drupal site someone else developed - and can't figure out which hook or module is responsible for putting various things on the page, rewriting queries, etc. etc., modules would have the opportunity (at some debug level) of telling you what they're doing as they do them. "Inserting WidgetX below page" etc. etc.. This would make runtime execution a lot more transparent and shorten code discovery time.

Login or register to post comments