OK, so you've said you tried the package and the source. I assume by this you've tried to pkg_add the tarball package, and when that didn't work you tried to install from pristine sources from the PHP distribution. If that's the case then there are more things you can try.
Here's the first, and simplest, way to go: get the ports tree from OpenBSD and install the port (cd to the appropriate dir and execute "sudo make install"), which will grab pristine source and patch it to fit the OpenBSD environment and then build from source. If you had an absolutely plain vanilla virgin 3.1 installation including the 3.1-release ports tree and performed a "make" in /usr/ports/www/php4 you'd end up with all the package tarballs in /usr/ports/packages/All -- and I mean exactly the same, bit for bit, as what you can download. Since you seem to be having problems with the downloaded package (have you done some of the security fix patches? That might be the source of your problems, I don't know for sure) then this route seems to me to be the most promising; in any event it should take into account any vagaries your system may have garnered since your install. If it compiles and installs without errors you should be good to go.
The next option is to use CVS and update your entire system to the 3.1-stable level and do the same in the packages tree -- this is more work by a long shot but is more likely to provide you with a stable properly functioning system, not to mention having all the latest stability and security fixes applied system-wide.
Let me know if any of this is unclear.