What class entries should be used to throw exceptions due to the default exception from the C extension?

In my C extension, I can pass a PHP exception to the calling function using zend_throw_exception . The first parameter to this function is zend_class_entry , which determines the type of exception. I know from the documentation in zend_exceptions.h that I can use zend_exception_get_default() to use the default exception type.

But he also says that I can pass a derived class. Where can I find class entries for received built-in exceptions like InvalidArgumentException ?

+8
c php php-extension
source share
1 answer

All exceptions are defined here in the source code;

  php-5.5.15/ext/spl/spl_exceptions.h 

and can be found here when you install the devel package (for example, yum install php-devel in Fedora);

  /usr/include/php/ext/spl/spl_exceptions.h 

and contains the following:

 extern PHPAPI zend_class_entry *spl_ce_LogicException; extern PHPAPI zend_class_entry *spl_ce_BadFunctionCallException; extern PHPAPI zend_class_entry *spl_ce_BadMethodCallException; extern PHPAPI zend_class_entry *spl_ce_DomainException; extern PHPAPI zend_class_entry *spl_ce_InvalidArgumentException; extern PHPAPI zend_class_entry *spl_ce_LengthException; extern PHPAPI zend_class_entry *spl_ce_OutOfRangeException; extern PHPAPI zend_class_entry *spl_ce_RuntimeException; extern PHPAPI zend_class_entry *spl_ce_OutOfBoundsException; extern PHPAPI zend_class_entry *spl_ce_OverflowException; extern PHPAPI zend_class_entry *spl_ce_RangeException; extern PHPAPI zend_class_entry *spl_ce_UnderflowException; extern PHPAPI zend_class_entry *spl_ce_UnexpectedValueException; 

and can, in accordance with the unit test, be selected as;

 zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "array size cannot be less than zero"); 
+7
source share

All Articles