Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm getting this warning in my Watchdog log when viewing my list of referers:
Warning: A non-numeric value encountered in Drupal\visitors\Controller\Report\Referers->_getData() (line 144 of /var/www/mysiteweb/modules/contrib/visitors/src/Controller/Report/Referers.php).
Here's the code in question:
143 $page = isset($_GET['page']) ? (int) $_GET['page'] : '';
144 $i = 0 + $page * $items_per_page;
The issue here is that $page can get set to a string value if the expression evaluates to FALSE. Here's the fix:
143 $page = isset($_GET['page']) ? (int) $_GET['page'] : 0;
Comment | File | Size | Author |
---|---|---|---|
#7 | warning_non_numeric_value-encountered-3090532-7.patch | 2.48 KB | sah62 |
#5 | warning_non_numeric_value-encountered-3090532-5.patch | 5.22 KB | fjgarlin |
#2 | visitors-3090532-2.patch | 504 bytes | sah62 |
Issue fork visitors-3090532
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:
Comments
Comment #2
sah62 CreditAttribution: sah62 commentedAdding a patch...
Comment #3
fjgarlin CreditAttribution: fjgarlin as a volunteer commentedComment #4
fjgarlin CreditAttribution: fjgarlin as a volunteer commentedI confirm that without the patch we get the watchdog entry and with the patch we no longer get it. Thanks.
Comment #5
fjgarlin CreditAttribution: fjgarlin as a volunteer commentedActually, whilst navigating through the different pages I got the error again, but from other pages. Then I looked into the module's code and saw that the same snippet appears in multiple places.
I attach a patch that fixes the issue wherever it appears.
Comment #6
sah62 CreditAttribution: sah62 commentedThe most recent patch works fine on my site. Thanks for the more thorough review!
Comment #7
sah62 CreditAttribution: sah62 commentedRe-roll for 8.x-2.7.
Comment #8
sah62 CreditAttribution: sah62 commentedUpdating the version to 8.x-2.6 because there's no option for 8.x-2.7.
Comment #14
bluegeek9 CreditAttribution: bluegeek9 as a volunteer commented