Multiple fixes

Workaround for <https://bugs.php.net/bug.php?id=53467> on PHP 5.4 and PHP 5.5 on OS X Mavericks (and probably others).