zumba / swivel

Strategy driven, segmented feature toggles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP 7 incompatibility - negative bit shift

ctrlrsf opened this issue · comments

While testing PHP 7 for admin app ran into incompatibility in swivel library. On line https://github.com/zumba/swivel/blob/master/src/Map.php#L225 when $index is 0, we end up doing a negative bit shift, which throws an ArithmeticError.

(Line 202 in stack trace is actually 225 in latest version of swivel library)

Fatal error: Uncaught ArithmeticError: Bit shift by negative number in /var/www/admin/releases/local_source/app/Vendor/zumba/swivel/src/Map.php:202 Stack trace: #0 [internal function]: Zumba\Swivel\Map->Zumba\Swivel\{closure}(NULL, '') #1 /var/www/admin/releases/local_source/app/Vendor/zumba/swivel/src/Map.php(203): array_reduce(Array, Object(Closure)) #2 [internal function]: Zumba\Swivel\Map->reduceToBitmask(Array) #3 /var/www/admin/releases/local_source/app/Vendor/zumba/swivel/src/Map.php(214): array_map(Array, Array) #4 /var/www/admin/releases/local_source/app/Vendor/zumba/swivel/src/Map.php(35): Zumba\Swivel\Map->parse(Array) #5 /var/www/admin/releases/local_source/app/Vendor/zumba/swivel/src/Config.php(102): Zumba\Swivel\Map->__construct(Array, Object(Zumba\Swivel\Logging\NullLogger)) #6 /var/www/admin/releases/local_source/app/Vendor/zumba/swivel/src/Config.php(50): Zumba\Swivel\Config->setMap(Array) #7 /var/www/admin/releases/local_source/app/Plugin/Swivel/Lib/SwivelLoader.php(57): Zumba\Swivel\Config->__construct( in /var/www/admin/releases/local_source/app/Vendor/zumba/swivel/src/Map.php on line 202

Line in swivel library causing issue:
https://github.com/zumba/swivel/blob/master/src/Map.php#L225

Reference:
http://php.net/manual/en/migration70.incompatible.php

Relevant section:

Negative bitshifts ¶

Bitwise shifts by negative numbers will now throw an ArithmeticError:

<?php
var_dump(1 >> -1);
?>
Output of the above example in PHP 5:

int(0)
Output of the above example in PHP 7:

Fatal error: Uncaught ArithmeticError: Bit shift by negative number in /tmp/test.php:2
Stack trace:
#0 {main}
  thrown in /tmp/test.php on line 2