There are a couple of docs about writing PHP extensions ..
There's the zend API info wich includes examples of hacking the PHP core..
http://www.zend.com/zend/api.php
In PHP's manual theres a section about adding stuff to PHP3:
http://www.php.net/manual/en/phpdevel.php
And there's also this document:
http://www.uk.research.att.com/~qsf/phpmodule/
good luck and if you do hack something new please share it 🙂