Fix some PHP compatibility issues. Tested in production. No caching yet.