Forward port the fixes from 6.x which where mostly done but cleanup extra lines added to the top of php files and some slight mistakes.