Another co-worker and I have been heavily modifying the PHP Zookeeper extension but the one thing really bothering me is the reliance on PHP error’s vs Exceptions.
The original source is here: http://github.com/andreiz/php-zookeeper/blob/master/php_zookeeper.c#L209
Instead it would be nicer to throw up a Zookeeper_NodeNotExists or similar except I have no idea what the API call in c is.
I’ve tried googling and got a cornucopia result set of Exceptions in the PHP language, the PHP manual doesn’t seem to mention them, and I can’t remember which PHP stock extensions throw exception for you. Is there an alternative source of documentation on the PHP/Zend c API out there?
I looked at the source code for PHP 5.3’s Sqlite extension, specifically Sqlite.c which I knew threw an exception and found
via sqlite – https://github.com/php/php-src/blob/PHP-5.3/ext/sqlite/sqlite.c#L46
In zend_exceptions.h, it looks like a RuntimeException can be raised via a simple call to
as explained here https://github.com/php/php-src/blob/PHP-5.3/Zend/zend_exceptions.h#L43
The Sqlite3 extension uses it like so:
where I infer that zend_exception_get_default() gets a reference/handle to RuntimeException, the 2nd argument is the Exception message, and all other work is delegated.