Prefer drupal_debug() to the now-ambiguous dd()

Created on 27 March 2023, over 1 year ago
Updated 11 September 2023, 10 months ago

Problem/Motivation

The views_debug() function calls dd(), expecting to get the devel module function.

Devel defines dd() as a shorthand for calling drupal_debug().

Drush uses the symfony/var-dumper library which in recent versions has introduced a dd() function in the global namespace (which seems somewhat ironic for an OOP-obsessed framework, but there we are).

Both symfony/var-dumper and devel have both 'addressed' this issue in the same way:

if (!function_exists('dd')) {
  function dd(...) {
    ...
  }
}

This prevents PHP parse errors but, depending on the request, Views can't know which function it's going to end up calling.

Steps to reproduce

Refer to:

In: web/sites/all/modules/development/devel/devel.module
1 [dd] function dd($data, $label = NULL) {

In: .composer/vendor/symfony/var-dumper/Resources/functions/dump.php
2 [dd] function dd(...$vars)

Proposed resolution

Use drupal_debug() directly.

A shorthand is useful in a REPL, but committed code should prefer the 'real' name -- even without the clash there's a micro-efficiency in not calling a wrapper function; but with the clash it's important to use the dependable name.

diff --git a/views.module b/views.module
index b62e4390..df7f490c 100644
--- a/views.module
+++ b/views.module
@@ -1861,7 +1861,7 @@ function views_debug($message, $placeholders = array()) {
     }
     elseif ($devel_region == 'drupal_debug') {
       $output = empty($output) ? t($message, $placeholders) : $output;
-      dd($output);
+      drupal_debug($output);
     }
     else {
       $output = empty($output) ? t($message, $placeholders) : $output;
πŸ› Bug report
Status

Fixed

Version

3.0

Component

Miscellaneous

Created by

πŸ‡³πŸ‡ΏNew Zealand jweowu

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

Comments & Activities

Production build 0.69.0 2024