Adding "clear context" functionality as well as fixing some PHP 4 reference issues

I've had this code committed for a year now and just now it occurred to me that as this could actually get merged with a pull request.