Shut up "Trying to access array offset on value of type null" notice

Created on 7 March 2021, almost 4 years ago
Updated 4 November 2023, over 1 year ago

Problem/Motivation

I usually see in the log:

Notice: Trying to access array offset on value of type null at Drupal\typogrify\SmartyPants::process() (lรญnia 263 de /var/www/web/modules/contrib/typogrify/src/SmartyPants.php)
#0 /var/www/web/core/includes/bootstrap.inc(305): _drupal_error_handler_real()
#1 /var/www/web/modules/contrib/typogrify/src/SmartyPants.php(263): _drupal_error_handler()
#2 /var/www/web/modules/contrib/typogrify/src/Typogrify.php(218): Drupal\typogrify\SmartyPants::process()

This is caused because process() function sets the $ctx variable to NULL by default:

/**
   * SmartyPants.
   *
   * @param string $text
   *   Text to be parsed.
   * @param string $attr
   *   Value of the smart_quotes="" attribute.
   * @param string $ctx
   *   MT context object (unused).
   *
   * @return string
   *   The modified text.
   */
  public static function process($text, $attr = NULL, $ctx = NULL) {
...

and later tries to access it as an array:

if ($do_quotes == 2) {
  $doc_lang = $ctx['langcode'];
}

But because $ctx is currently unused, it is always null.

๐Ÿ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

pere orga Catalonia

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.71.5 2024