diff --git a/includes/common.inc b/includes/common.inc index 045dd9b3032..5fe47dc42cc 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1179,7 +1179,7 @@ function format_xml_elements($array) { $output = ''; foreach ($array as $key => $value) { if (is_numeric($key)) { - if ($value['key']) { + if (!empty($value['key'])) { $output .= ' <'. $value['key']; if (isset($value['attributes']) && is_array($value['attributes'])) { $output .= drupal_attributes($value['attributes']); @@ -2041,6 +2041,19 @@ function drupal_build_css_cache($types, $filename) { * Helper function for drupal_build_css_cache(). * * This function will prefix all paths within a CSS file. + * + * @param array|null $matches + * A 'matches' array as would be populated by e.g. preg_match() - meaning + * $matches[0] has text that matched the full pattern and $matches[1] has + * text that matched the first captured parenthesized subpattern. We assume + * $matchesIf NULL, + * then don't return anything useful; only set the base path for future calls. + * @param string|null $base + * The base path to use for prefixing. + * + * @return string|null + * A CSS path (prefixed, and surrounded with "url()" - or NULL if the first + * parameter was NULL. */ function _drupal_build_css_path($matches, $base = NULL) { static $_base; @@ -2048,6 +2061,9 @@ function _drupal_build_css_path($matches, $base = NULL) { if (isset($base)) { $_base = $base; } + if (!isset($matches[1])) { + return NULL; + } // Prefix with base and remove '../' segments where possible. $path = $_base . $matches[1]; diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc index 1b2a2382b96..bd729f4f8dd 100644 --- a/includes/database.mysql.inc +++ b/includes/database.mysql.inc @@ -192,7 +192,11 @@ function db_result($result) { // The mysql_fetch_row function has an optional second parameter $row // but that can't be used for compatibility with Oracle, DB2, etc. $array = mysql_fetch_row($result); - return $array[0]; + // This function was never meant to be used multiple times on the same + // result set (resulting in $array being FALSE). But the above spec is not + // absolutely clear about that, so various code is doing it, and PHP < 7.4 + // didn't emit any PHP Notices. So now, we effectively support it... + return isset($array[0]) ? $array[0] : FALSE; } return FALSE; } diff --git a/includes/database.mysqli.inc b/includes/database.mysqli.inc index b373730eabc..b08c12f44f4 100644 --- a/includes/database.mysqli.inc +++ b/includes/database.mysqli.inc @@ -192,7 +192,11 @@ function db_result($result) { // The mysqli_fetch_row function has an optional second parameter $row // but that can't be used for compatibility with Oracle, DB2, etc. $array = mysqli_fetch_row($result); - return $array[0]; + // This function was never meant to be used multiple times on the same + // result set (resulting in $array being NULL). But the above spec is not + // absolutely clear about that, so various code is doing it, and PHP < 7.4 + // didn't emit any PHP Notices. So now, we effectively support it... + return isset($array[0]) ? $array[0] : FALSE; } return FALSE; } diff --git a/includes/database.pgsql.inc b/includes/database.pgsql.inc index da7c4f970a4..7aff4d13167 100644 --- a/includes/database.pgsql.inc +++ b/includes/database.pgsql.inc @@ -206,7 +206,11 @@ function db_fetch_array($result) { function db_result($result) { if ($result && pg_num_rows($result) > 0) { $array = pg_fetch_row($result); - return $array[0]; + // This function was never meant to be used multiple times on the same + // result set (resulting in $array being FALSE). But the above spec is not + // absolutely clear about that, so various code is doing it, and PHP < 7.4 + // didn't emit any PHP Notices. So now, we effectively support it... + return isset($array[0]) ? $array[0] : FALSE; } return FALSE; } diff --git a/includes/menu.inc b/includes/menu.inc index 4788855415d..442b62e5372 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -1539,7 +1539,7 @@ function menu_set_active_trail($new_trail = NULL) { $item = menu_get_item(); // Check whether the current item is a local task (displayed as a tab). - if ($item['tab_parent']) { + if (!empty($item['tab_parent'])) { // The title of a local task is used for the tab, never the page title. // Thus, replace it with the item corresponding to the root path to get // the relevant href and title. For example, the menu item corresponding @@ -1580,7 +1580,7 @@ function menu_set_active_trail($new_trail = NULL) { // Make sure the current page is in the trail (needed for the page title), // but exclude tabs and the front page. $last = count($trail) - 1; - if ($trail[$last]['href'] != $item['href'] && !(bool)($item['type'] & MENU_IS_LOCAL_TASK) && !drupal_is_front_page()) { + if ($item && $trail[$last]['href'] != $item['href'] && !(bool)($item['type'] & MENU_IS_LOCAL_TASK) && !drupal_is_front_page()) { $trail[] = $item; } } diff --git a/modules/block/block.admin.inc b/modules/block/block.admin.inc index 3fd8280a9c7..3beafefeb70 100644 --- a/modules/block/block.admin.inc +++ b/modules/block/block.admin.inc @@ -160,7 +160,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) { '#title' => t('Block title'), '#maxlength' => 64, '#description' => $module == 'block' ? t('The title of the block as shown to the user.') : t('Override the default title for the block. Use <none> to display no title, or leave blank to use the default block title.'), - '#default_value' => $edit['title'], + '#default_value' => $edit ? $edit['title'] : NULL, '#weight' => -18, ); @@ -193,7 +193,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) { t('Hide this block by default but let individual users show it.') ), '#description' => t('Allow individual users to customize the visibility of this block in their account settings.'), - '#default_value' => $edit['custom'], + '#default_value' => $edit ? $edit['custom'] : NULL, ); // Role-based visibility settings @@ -227,7 +227,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) { ); $access = user_access('use PHP for block visibility'); - if ($edit['visibility'] == 2 && !$access) { + if ($edit && $edit['visibility'] == 2 && !$access) { $form['page_vis_settings'] = array(); $form['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => 2); $form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $edit['pages']); @@ -244,12 +244,12 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) { '#type' => 'radios', '#title' => t('Show block on specific pages'), '#options' => $options, - '#default_value' => $edit['visibility'], + '#default_value' => $edit ? $edit['visibility'] : NULL, ); $form['page_vis_settings']['pages'] = array( '#type' => 'textarea', '#title' => t('Pages'), - '#default_value' => $edit['pages'], + '#default_value' => $edit ? $edit['pages'] : NULL, '#description' => $description, ); } diff --git a/modules/book/book.module b/modules/book/book.module index 37d8c06f135..31c451821ad 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -860,7 +860,7 @@ function _book_toc_recurse($tree, $indent, &$toc, $exclude, $depth_limit) { * @return * An array of mlid, title pairs for use as options for selecting a book page. */ -function book_toc($bid, $exclude = array(), $depth_limit) { +function book_toc($bid, $exclude, $depth_limit) { $tree = menu_tree_all_data(book_menu_name($bid)); $toc = array(); diff --git a/modules/comment/comment.admin.inc b/modules/comment/comment.admin.inc index 62120490fcd..38c1cfa85a4 100644 --- a/modules/comment/comment.admin.inc +++ b/modules/comment/comment.admin.inc @@ -33,7 +33,7 @@ function comment_admin($type = 'new') { * @see comment_admin_overview_submit() * @see theme_comment_admin_overview() */ -function comment_admin_overview($type = 'new', $arg) { +function comment_admin_overview($type, $arg) { // build an 'Update options' form $form['options'] = array( '#type' => 'fieldset', '#title' => t('Update options'), diff --git a/modules/contact/contact.admin.inc b/modules/contact/contact.admin.inc index e7a5defd08b..bd71f4f45e1 100644 --- a/modules/contact/contact.admin.inc +++ b/modules/contact/contact.admin.inc @@ -22,7 +22,7 @@ function contact_admin_categories() { /** * Category edit page. */ -function contact_admin_edit($form_state = array(), $op, $contact = NULL) { +function contact_admin_edit($form_state, $op, $contact = NULL) { if (empty($contact) || $op == 'add') { $contact = array( diff --git a/modules/dblog/dblog.admin.inc b/modules/dblog/dblog.admin.inc index 853a2ce14c8..3448bd00026 100644 --- a/modules/dblog/dblog.admin.inc +++ b/modules/dblog/dblog.admin.inc @@ -191,8 +191,10 @@ function dblog_build_filter_query() { foreach ($_SESSION['dblog_overview_filter'] as $key => $filter) { $filter_where = array(); foreach ($filter as $value) { - $filter_where[] = $filters[$key]['where']; - $args[] = $value; + if (isset($filters[$key]['where'])) { + $filter_where[] = $filters[$key]['where']; + $args[] = $value; + } } if (!empty($filter_where)) { $where[] = '('. implode(' OR ', $filter_where) .')'; diff --git a/modules/forum/forum.module b/modules/forum/forum.module index d656f109012..58e7e05cf75 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -582,7 +582,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) { ); $order = _forum_get_topic_order($sortby); - for ($i = 0; $i < count($forum_topic_list_header); $i++) { + for ($i = 1; $i < count($forum_topic_list_header); $i++) { if ($forum_topic_list_header[$i]['field'] == $order['field']) { $forum_topic_list_header[$i]['sort'] = $order['sort']; } diff --git a/modules/user/user.module b/modules/user/user.module index 5ff9a35a361..b5f272f1d18 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1533,7 +1533,7 @@ function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) { if ($register || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || $admin) { $form['account']['name'] = array('#type' => 'textfield', '#title' => t('Username'), - '#default_value' => $edit['name'], + '#default_value' => isset($edit['name']) ? $edit['name'] : NULL, '#maxlength' => USERNAME_MAX_LENGTH, '#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'), '#required' => TRUE, @@ -1541,7 +1541,7 @@ function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) { } $form['account']['mail'] = array('#type' => 'textfield', '#title' => t('E-mail address'), - '#default_value' => $edit['mail'], + '#default_value' => isset($edit['mail']) ? $edit['mail'] : NULL, '#maxlength' => EMAIL_MAX_LENGTH, '#description' => t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), '#required' => TRUE,