avoid Drupal API function calls in global context

Created on 19 May 2017, about 7 years ago
Updated 27 February 2023, over 1 year ago

The current D7 release (7.x-1.13) of this module has this at the very beginning of the .module file:

$mfw_path = drupal_get_path('module', 'multiupload_filefield_widget');             
require_once $mfw_path . '/multiupload_filefield_widget.field.inc'; 

In the 7.x-1.x branch, this has been changed to:

module_load_include('inc', 'multiupload_filefield_widget', 'multiupload_filefield_widget.field');

Either of these could cause problems as they're calling Drupal API functions before Drupal is fully bootstrapped. See, for example the docs for module_load_include which say:

Do not use this function in a global context since it requires Drupal to be fully bootstrapped

As the .inc file is in the same directory as the module file, the function calls could be replaced with something as simple as:

require_once __DIR__ . '/multiupload_filefield_widget.field.inc';

Calling Drupal functions "inline" can cause performance problems and have unpredictable consequences such as "cache poisoning", so it's definitely worth avoiding this.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom mcdruid πŸ‡¬πŸ‡§πŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024