Skip to content

Excluding IPs doesn't work on php7 #10373

@andrzejewsky

Description

@andrzejewsky

Las time when we were testing Piwik with the newest version of PHP. Actually, everything looks promising except small error which arose during archivization process.

This problem is about bit-shifting in this class: https://github.com/piwik/component-network/blob/0.2.0/src/IPUtils.php.
Look at line https://github.com/piwik/component-network/blob/0.2.0/src/IPUtils.php#L182
Sometimes variable $n is a negative number and in the PHP7 it will throw an exception because this version of PHP introduced exceptions instead of fatal errors, null values etc.

small example:

// php 5.6
var_dump(1 << 1); // int(2)
var_dump(1 << -1); // int(-9223372036854775808)
var_dump(-1 << 1); // int(-2)
var_dump(~((1 << $n) - 1)); // int(9223372036854775807) when $n = -1

// php 7
var_dump(1 << 1); // int(2)
var_dump(1 << -1); // Uncaught ArithmeticError: Bit shift by negative number
var_dump(-1 << 1); // int(-2)
var_dump(~((1 << $n) - 1)); // Uncaught ArithmeticError: Bit shift by negative number  when $n = -1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugFor errors / faults / flaws / inconsistencies etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions