Skip to content

Commit 8838b38

Browse files
author
Andi Gutmans
committed
Patch by Timm Friebe:
It changes set_exception_handler() to accept the pseudo-type "callable" (instead of a string referring to a global function). Examples: set_exception_handler('function_name'); set_exception_handler(array('class_name', 'static_method')); set_exception_handler(array($instance, 'instance_method')); This also makes set_exception_handler() more consistent with all the other callback functionality, e.g. set_error_handler().
1 parent efb62ea commit 8838b38

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Zend/zend_builtin_functions.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,18 +1009,26 @@ ZEND_FUNCTION(restore_error_handler)
10091009
/* }}} */
10101010

10111011

1012-
/* {{{ proto string set_exception_handler(string exception_handler)
1012+
/* {{{ proto string set_exception_handler(callable exception_handler)
10131013
Sets a user-defined exception handler function. Returns the previously defined exception handler, or false on error */
10141014
ZEND_FUNCTION(set_exception_handler)
10151015
{
10161016
zval **exception_handler;
1017+
char *exception_handler_name = NULL;
10171018
zend_bool had_orig_exception_handler=0;
10181019

10191020
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &exception_handler)==FAILURE) {
10201021
ZEND_WRONG_PARAM_COUNT();
10211022
}
10221023

1023-
convert_to_string_ex(exception_handler);
1024+
if (!zend_is_callable(*exception_handler, 0, &exception_handler_name)) {
1025+
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
1026+
get_active_function_name(TSRMLS_C), exception_handler_name?exception_handler_name:"unknown");
1027+
efree(exception_handler_name);
1028+
return;
1029+
}
1030+
efree(exception_handler_name);
1031+
10241032
if (EG(user_exception_handler)) {
10251033
had_orig_exception_handler = 1;
10261034
*return_value = *EG(user_exception_handler);

0 commit comments

Comments
 (0)