php 5.3/4 compat resub

Changed too many lines in the last one.  Resubbing.
I was adding the project to Symfony and had to make a few changes. This should be closer to the PHP API spec while being backwards compatible.