More fixes backported from php.tools