Phpupgrade and some auto build related fixes

I have also made these changes in a private branch, but it requires many additional fixes to work correctly. I would wait with merging this, and I will put up a PR later.