Make sure Views is fully compatible with PHP 8.

Issue fork views-3207982

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna created an issue. See original summary.

DamienMcKenna’s picture

Issue tags: +DrupalFest2021
DamienMcKenna’s picture

I set up a testbot for PHP 8: https://www.drupal.org/pift-ci-job/2027110

DamienMcKenna’s picture

There are some errors noted..

I'm concerned at this one:

fail: [PHP Deprecated] Line 123 of sites/all/modules/views/plugins/views_plugin_query_default.inc:
 Required parameter $options follows optional parameter $base_table

I'm concerned that fixing this will require an API break.

There are some simpler things, e.g.:

exception: [Warning] Line 2433 of sites/all/modules/views/views.module:
Array to string conversion

and:

fail: [Other] Line 120 of sites/all/modules/views/tests/handlers/views_handler_filter_in_operator.test:
Value 2 is equal to value 0.

fail: [Other] Line 122 of sites/all/modules/views/tests/handlers/views_handler_filter_in_operator.test:
Identical result set

fail: [Other] Line 153 of sites/all/modules/views/tests/handlers/views_handler_filter_in_operator.test:
Value 3 is equal to value 5.

fail: [Other] Line 155 of sites/all/modules/views/tests/handlers/views_handler_filter_in_operator.test:
Identical result set

And this one:

exception: [Warning] Line 174 of sites/all/modules/views/tests/views_glossary.test:
Undefined array key 10

And:

fail: [Completion check] Line 54 of sites/all/modules/views/tests/comment/views_handler_argument_comment_user_uid.test:
The test did not complete due to a fatal error.
exception: [Warning] Line 1532 of modules/comment/comment.module:
Attempt to read property "thread" on bool
fail: [Other] Line 443 of sites/all/modules/views/tests/field/views_fieldapi.test:
Take sure that the amount of items are limited.

*cough* Yeah... some of these might be hard to fix without breaking anything.

DamienMcKenna’s picture

DamienMcKenna’s picture

Ayesh worked on views_plugin_query_default::init() in #3189937.

DamienMcKenna’s picture

DamienMcKenna’s picture

Status: Active » Needs review
DamienMcKenna’s picture

exception: [Warning] Line 2433 of sites/all/modules/views/views.module:
Array to string conversion

.. is going to be weird because it isn't clear which variable is causing the problem.

DamienMcKenna’s picture

Trying to fix _views_query_tag_alter_condition().

DamienMcKenna’s picture

This fixes the problem in _views_query_tag_alter_condition() by converting the nested array to a JSON string and converting it back again after the str_replace().

Status: Needs review » Needs work

The last submitted patch, 12: views-n3207982-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
1.3 KB

I rewrote the string replacement using array_walk_recursive().

Status: Needs review » Needs work

The last submitted patch, 14: views-n3207982-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
1.64 KB

Does this work?

DamienMcKenna’s picture

Ok, so at least it doesn't cause regressions.

DamienMcKenna’s picture

Trying to fix the comment tests.

DamienMcKenna’s picture

There's something funny with _testMultipleFieldRender(), the "Test delta first last" part fails to render properly with PHP 8. This adds an extra assertion to make sure the output renders.

DamienMcKenna’s picture

I've studied the data and there's a problem when "delta_first_last" is enabled on a field, for some reason the query doesn't return any data with PHP 8. I've confirmed this by disabling "delta_first_last" but leaving the other options as-is, the query returned data.

The only place that the option is used is in this code from views_handler_field_field::get_value():

      $new_values = array();
      for ($i = 0; $i < $delta_limit; $i++) {
        $new_delta = $offset + $i;

        if (isset($all_values[$new_delta])) {
          // If first-last option was selected only use the first and last
          // values, otherwise include all values.
          if (!$delta_first_last
            // Use the first value.
            || $new_delta == $offset
            // Use the last value.
            || $new_delta == ($delta_limit + $offset - 1)) {
            $new_values[] = $all_values[$new_delta];
          }
        }
      }

Status: Needs review » Needs work

The last submitted patch, 20: views-n3207982-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
9.61 KB

Try again.

Status: Needs review » Needs work

The last submitted patch, 22: views-n3207982-22.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
9.19 KB

Ok fine :p

Status: Needs review » Needs work

The last submitted patch, 24: views-n3207982-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

DamienMcKenna’s picture

Side-step.. attempting to fix the failures in cache handling.

DamienMcKenna’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 26: views-n3207982-26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • DamienMcKenna committed 75ea48e on 7.x-3.x
    Issue #3207982 by DamienMcKenna: PHP 8.0 compatibility fixes.
    
DamienMcKenna’s picture

To move things along I've committed #19.

MustangGB’s picture

What a roller coaster.

DamienMcKenna’s picture

The last problems seems to be:

  • ViewsCacheTest
    gather_headers
    exception: [Warning] Line 203 of sites/all/modules/views/plugins/views_plugin_cache.inc:
    Array to string conversion
    (repeated a bunch of times)
  • viewsHandlerFieldFieldTest
    _testMultipleFieldRender
    fail: [Other] Line 442 of sites/all/modules/views/tests/field/views_fieldapi.test:
    Value NULL is not NULL.
    fail: [Other] Line 447 of sites/all/modules/views/tests/field/views_fieldapi.test:
    Take sure that the amount of items are limited.
    (repeated twice more)
Taran2L’s picture

I've given it a bit of attention and here are my thoughts:

1. The caching issue seems like .. hm .. weird. I (almost) believe that actual code does not do anything, because in older version of PHP it just returns the $subject array (because our array are multidimensional). PHP8.0+ expects a one dimensional array, thus the error:

$this->storage['head'] = str_replace($this->storage['head'], '', drupal_add_html_head());

2. The _testMultipleFieldRender issue is even trickier. I think there is an error in the test itself:

    // Test delta first last.
    ....
    $view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 0;
    ....

The limit is 0, so yes, there are no results. The only thing that bothers me there is: how come it worked before.

Taran2L’s picture

Update re #1. So, actually head part does not work at all, just because later in views_plugin_cache::restore_headers() the following part is incorrect:

if (!empty($this->storage['head'])) {
  drupal_add_html_head($this->storage['head']);
}

And drupal_add_html_head() requires both $data and $key to be set:

/**
 * Adds output to the HEAD tag of the HTML page.
 *
 * This function can be called as long as the headers aren't sent. Pass no
 * arguments (or NULL for both) to retrieve the currently stored elements.
 *
 * @param $data
 *   A renderable array. If the '#type' key is not set then 'html_tag' will be
 *   added as the default '#type'.
 * @param $key
 *   A unique string key to allow implementations of hook_html_head_alter() to
 *   identify the element in $data. Required if $data is not NULL.
 *
 * @return
 *   An array of all stored HEAD elements.
 *
 * @see theme_html_tag()
 */
function drupal_add_html_head($data = NULL, $key = NULL) {
  $stored_head = &drupal_static(__FUNCTION__);

  if (!isset($stored_head)) {
    // Make sure the defaults, including Content-Type, come first.
    $stored_head = _drupal_default_html_head();
  }

  if (isset($data) && isset($key)) {
    if (!isset($data['#type'])) {
      $data['#type'] = 'html_tag';
    }
    $stored_head[$key] = $data;
  }
  return $stored_head;
}

Update re #2, in PHP < 8.0 the following code evaluates to true, see https://3v4l.org/iXBHf

if ($delta_limit == 'all') {
  $delta_limit = count($all_values) - $offset;
}

Alright, then #2 is a test issue :)

Taran2L’s picture

Status: Needs work » Needs review
Taran2L’s picture

DamienMcKenna’s picture

Great work, thank you!

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. Thanks Taran2L!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.