Reintroduce fix from pull #770 in a PHP 7 way