Problem/Motivation

template_preprocess_pager() passes a $quantity variable into the ceil() function without making sure that it is an integer (or a number for that matter). As a result, PHP 7.1 (and greater) complains:

A non-numeric value encountered

Proposed resolution

Casting the $quantity variable into an (int) should get rid of the warning.

Remaining tasks

Provide a patch.

Original report by [SergFromSD] in #2902430: [D7] PHP 7.1 warning: A non-numeric value encountered in theme_pager()

N.B.: Attached is a dummy patch that demonstrates the problem,
it ran as part of this comment #2902430-35: [D7] PHP 7.1 warning: A non-numeric value encountered in theme_pager()
results were reported here https://www.drupal.org/pift-ci-job/1473318

Comments

stefanos.petrakis created an issue. See original summary.

stefanos.petrakis’s picture

Status: Active » Needs review
StatusFileSize
new1.88 KB
new0 bytes
new2.52 KB

Updated and rerolling the testing code, need it to to demonstrate before and after applying the patch.

Adding a patch as well.

stefanos.petrakis’s picture

stefanos.petrakis’s picture

The last submitted patch, 2: d8_failing_test_non_numeric_value_take3.patch, failed testing. View results

avpaderno’s picture

Title: php 7.1 Warning: A non-numeric value encountered in theme_pager() » PHP 7.1 warning: A non-numeric value encountered in theme_pager()
avpaderno’s picture

Status: Needs review » Reviewed & tested by the community

This is quite straight. It's the same issue Drupal 7 has, and the fix is the same.

mcdruid’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.88 KB
new2.52 KB

Thanks for working on this @stefanos.petrakis - this is great!

I think the standard approach is to have a test-only patch which illustrates the problem by failing, then a patch which includes the test and the change which fixes the issue.

That's what you've provided in #2 and I think that's what we should leave as the patch we're proposing be committed.

I'll upload the patches again following the standard naming convention just for clarity, but these are @stefanos.petrakis's patches without changes.

The last submitted patch, 9: 3094536-9_test_only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 9: 3094536-9.patch, failed testing. View results

mcdruid’s picture

Title: PHP 7.1 warning: A non-numeric value encountered in theme_pager() » PHP 7.1 warning: A non-numeric value encountered in template_preprocess_pager()

Oh... the test fails as a "Risky Test" even with the change. IIUC that's because it doesn't actually do anything beyond trigger the PHP Warning.

I'm trying to establish whether we should fix the test properly (there's a @TODO comment as well) or just remove it.

alexpott’s picture

+++ b/core/includes/pager.inc
@@ -185,7 +185,7 @@ function pager_get_query_parameters() {
-  $quantity = $variables['pager']['#quantity'];
+  $quantity = (int) $variables['pager']['#quantity'];

I think we should do $quantity = empty($variables['pager']['#quantity']) ? 0 : $variables['pager']['#quantity'];. Using (int) potentially hides helpful warning if you do actually pass a value like 'a_string_value' in.

It's a risky test because it is not making an assertion. It's verifying the absence of something - there needs to be a positive assertion.

mcdruid’s picture

Title: PHP 7.1 warning: A non-numeric value encountered in template_preprocess_pager() » PHP 7.1 Warning: A non-numeric value encountered in template_preprocess_pager()
Status: Needs work » Needs review
StatusFileSize
new2.07 KB
new2.75 KB
new1.32 KB

Per @alexpott's suggestion new patch which handles an empty #quantity specifically.

Tidied up the test and added a basic assertion.

The last submitted patch, 14: 3094536-14_test_only.patch, failed testing. View results

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC - Looks good to me.

Thanks, alexpott for the feedback that the original patch was better than casting to int.

alexpott’s picture

Version: 8.9.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed and pushed bd584c5719 to 9.0.x and f8c7a35ac5 to 8.9.x. Thanks!

I think we should backport this to 8.8.x as per process asking another committer for a +1 because we're in beta.

  • alexpott committed bd584c5 on 9.0.x
    Issue #3094536 by stefanos.petrakis, mcdruid, alexpott: PHP 7.1 Warning...

  • alexpott committed f8c7a35 on 8.9.x
    Issue #3094536 by stefanos.petrakis, mcdruid, alexpott: PHP 7.1 Warning...
alexpott’s picture

Status: Patch (to be ported) » Fixed

@catch +1'd the fix.

  • alexpott committed 2ce5784 on 8.8.x
    Issue #3094536 by stefanos.petrakis, mcdruid, alexpott: PHP 7.1 Warning...

Status: Fixed » Closed (fixed)

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