summaryrefslogtreecommitdiff
path: root/Zend/zend_interfaces.c
diff options
context:
space:
mode:
authorAaron Piotrowski <aaron@trowski.com>2015-05-16 15:30:59 -0500
committerAaron Piotrowski <aaron@trowski.com>2015-05-16 15:30:59 -0500
commitd042d0880796cfe99262bb6fa44225e984c63ace (patch)
treeeb428c9c3d43c4ab9c230b86eeaceccd01e42120 /Zend/zend_interfaces.c
parentc9f27ee4227268bc74fc54e0e06102317e614804 (diff)
downloadphp-git-d042d0880796cfe99262bb6fa44225e984c63ace.tar.gz
Remodel exceptions based on Throwable interface
Added Throwable interface that exceptions must implement in order to be thrown. BaseException was removed, EngineException renamed to Error, and TypeException and ParseException renamed to TypeError and ParseError. Exception and Error no longer extend a common base class, rather they both implement the Throwable interface.
Diffstat (limited to 'Zend/zend_interfaces.c')
-rw-r--r--Zend/zend_interfaces.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c
index 54f8f8c117..2b8f8a25bc 100644
--- a/Zend/zend_interfaces.c
+++ b/Zend/zend_interfaces.c
@@ -28,6 +28,7 @@ ZEND_API zend_class_entry *zend_ce_aggregate;
ZEND_API zend_class_entry *zend_ce_iterator;
ZEND_API zend_class_entry *zend_ce_arrayaccess;
ZEND_API zend_class_entry *zend_ce_serializable;
+ZEND_API zend_class_entry *zend_ce_throwable;
/* {{{ zend_call_method
Only returns the returned zval if retval_ptr != NULL */
@@ -502,6 +503,19 @@ static int zend_implement_serializable(zend_class_entry *interface, zend_class_e
}
/* }}}*/
+/* {{{ zend_implement_traversable */
+static int zend_implement_throwable(zend_class_entry *interface, zend_class_entry *class_type)
+{
+ if (instanceof_function(class_type, zend_exception_get_default()) || instanceof_function(class_type, zend_get_error())) {
+ return SUCCESS;
+ }
+ zend_error_noreturn(E_CORE_ERROR, "Class %s cannot implement interface %s, extend Exception instead",
+ class_type->name->val,
+ interface->name->val);
+ return FAILURE;
+}
+/* }}} */
+
/* {{{ function tables */
const zend_function_entry zend_funcs_aggregate[] = {
ZEND_ABSTRACT_ME(iterator, getIterator, NULL)
@@ -551,6 +565,8 @@ const zend_function_entry zend_funcs_serializable[] = {
};
/* }}} */
+const zend_function_entry *zend_funcs_throwable = NULL;
+
#define REGISTER_ITERATOR_INTERFACE(class_name, class_name_str) \
{\
zend_class_entry ce;\
@@ -575,7 +591,9 @@ ZEND_API void zend_register_interfaces(void)
REGISTER_ITERATOR_INTERFACE(arrayaccess, ArrayAccess);
- REGISTER_ITERATOR_INTERFACE(serializable, Serializable)
+ REGISTER_ITERATOR_INTERFACE(serializable, Serializable);
+
+ REGISTER_ITERATOR_INTERFACE(throwable, Throwable);
}
/* }}} */