PHP 4.1.2 compatibility fixes (based on patch submission by Asheesh Laroia)