From aa54af80a986fdcb201acb15d9c8f8100cd94649 Mon Sep 17 00:00:00 2001 From: Ferenc Kovacs Date: Tue, 30 Dec 2014 19:15:03 +0100 Subject: [PATCH 1/3] introduce get_error_handler --- Zend/tests/error_handler_001.phpt | 32 +++++++++++++++++++++++++++ Zend/tests/exception_handler_007.phpt | 30 +++++++++++++++++++++++++ Zend/zend_builtin_functions.c | 24 ++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 Zend/tests/error_handler_001.phpt create mode 100644 Zend/tests/exception_handler_007.phpt diff --git a/Zend/tests/error_handler_001.phpt b/Zend/tests/error_handler_001.phpt new file mode 100644 index 0000000000000..23c0ad131b956 --- /dev/null +++ b/Zend/tests/error_handler_001.phpt @@ -0,0 +1,32 @@ +--TEST-- +error handler tests - 1 +--FILE-- + +--EXPECTF-- +NULL +NULL +int(512) +string(4) "test" +string(%d) "%s/Zend/tests/error_handler_001.php" +int(7) +bool(true) +NULL +Done + diff --git a/Zend/tests/exception_handler_007.phpt b/Zend/tests/exception_handler_007.phpt new file mode 100644 index 0000000000000..58f2526d63494 --- /dev/null +++ b/Zend/tests/exception_handler_007.phpt @@ -0,0 +1,30 @@ +--TEST-- +exception handler tests - 1 +--FILE-- + +--EXPECTF-- +NULL +NULL +string(12) "test thrown!" +bool(true) +NULL diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 32f210e44c37a..bf2bce7fd8eb1 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -68,8 +68,10 @@ static ZEND_FUNCTION(get_object_vars); static ZEND_FUNCTION(get_class_methods); static ZEND_FUNCTION(trigger_error); static ZEND_FUNCTION(set_error_handler); +static ZEND_FUNCTION(get_error_handler); static ZEND_FUNCTION(restore_error_handler); static ZEND_FUNCTION(set_exception_handler); +static ZEND_FUNCTION(get_exception_handler); static ZEND_FUNCTION(restore_exception_handler); static ZEND_FUNCTION(get_declared_classes); static ZEND_FUNCTION(get_declared_traits); @@ -286,8 +288,10 @@ static const zend_function_entry builtin_functions[] = { /* {{{ */ ZEND_FE(trigger_error, arginfo_trigger_error) ZEND_FALIAS(user_error, trigger_error, arginfo_trigger_error) ZEND_FE(set_error_handler, arginfo_set_error_handler) + ZEND_FE(get_error_handler, arginfo_zend__void) ZEND_FE(restore_error_handler, arginfo_zend__void) ZEND_FE(set_exception_handler, arginfo_set_exception_handler) + ZEND_FE(get_exception_handler, arginfo_zend__void) ZEND_FE(restore_exception_handler, arginfo_zend__void) ZEND_FE(get_declared_classes, arginfo_zend__void) ZEND_FE(get_declared_traits, arginfo_zend__void) @@ -1656,6 +1660,16 @@ ZEND_FUNCTION(set_error_handler) } /* }}} */ +/* {{{ proto string get_error_handler(void) + Returns the currently defined error handler, or null */ +ZEND_FUNCTION(get_error_handler) +{ + if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) { + RETVAL_ZVAL(&EG(user_error_handler), 1, 0); + } +} +/* }}} */ + /* {{{ proto void restore_error_handler(void) Restores the previously defined error handler function */ ZEND_FUNCTION(restore_error_handler) @@ -1718,6 +1732,16 @@ ZEND_FUNCTION(set_exception_handler) } /* }}} */ +/* {{{ proto string get_exception_handler(void) + Returns the currently defined exception handler, or null */ +ZEND_FUNCTION(get_exception_handler) +{ + if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { + RETVAL_ZVAL(&EG(user_exception_handler), 1, 0); + } +} +/* }}} */ + /* {{{ proto void restore_exception_handler(void) Restores the previously defined exception handler function */ ZEND_FUNCTION(restore_exception_handler) From 5210048f6f962419bd439bcb3cc441d9d1bc0787 Mon Sep 17 00:00:00 2001 From: Ferenc Kovacs Date: Mon, 30 Mar 2015 16:46:20 +0200 Subject: [PATCH 2/3] use tabs instead of spaces --- Zend/zend_builtin_functions.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index bf2bce7fd8eb1..1a93d4b022f65 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1664,9 +1664,9 @@ ZEND_FUNCTION(set_error_handler) Returns the currently defined error handler, or null */ ZEND_FUNCTION(get_error_handler) { - if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) { - RETVAL_ZVAL(&EG(user_error_handler), 1, 0); - } + if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) { + RETVAL_ZVAL(&EG(user_error_handler), 1, 0); + } } /* }}} */ @@ -1736,9 +1736,9 @@ ZEND_FUNCTION(set_exception_handler) Returns the currently defined exception handler, or null */ ZEND_FUNCTION(get_exception_handler) { - if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { - RETVAL_ZVAL(&EG(user_exception_handler), 1, 0); - } + if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { + RETVAL_ZVAL(&EG(user_exception_handler), 1, 0); + } } /* }}} */ From 87f58d688522bae8306468b116897c284b23b955 Mon Sep 17 00:00:00 2001 From: Ferenc Kovacs Date: Mon, 30 Mar 2015 16:47:13 +0200 Subject: [PATCH 3/3] use zend_parse_parameters_none() as suggested by Kalle --- Zend/zend_builtin_functions.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 1a93d4b022f65..97e5b27ed66b8 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1664,6 +1664,10 @@ ZEND_FUNCTION(set_error_handler) Returns the currently defined error handler, or null */ ZEND_FUNCTION(get_error_handler) { + if (zend_parse_parameters_none() == FAILURE) { + return; + } + if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) { RETVAL_ZVAL(&EG(user_error_handler), 1, 0); } @@ -1736,6 +1740,10 @@ ZEND_FUNCTION(set_exception_handler) Returns the currently defined exception handler, or null */ ZEND_FUNCTION(get_exception_handler) { + if (zend_parse_parameters_none() == FAILURE) { + return; + } + if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { RETVAL_ZVAL(&EG(user_exception_handler), 1, 0); }