From 91388e3ce2679e5f7650f923bcba34719856f6ea Mon Sep 17 00:00:00 2001 From: Zach Neumann Date: Thu, 3 Aug 2023 10:03:47 -0600 Subject: [PATCH] additional context from PR #638 --- agent/php_call.c | 17 ++++++++++++++--- .../test_wordpress_apply_filters.php8.php | 4 ++++ .../wordpress/test_wordpress_do_action.php8.php | 4 ++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/agent/php_call.c b/agent/php_call.c index c811bddee..bb376b67c 100644 --- a/agent/php_call.c +++ b/agent/php_call.c @@ -43,9 +43,11 @@ static int nr_php_call_try_catch(zval* object_ptr, zval* param_values) { /* * With PHP8, `call_user_function_ex` was removed and `call_user_function` - * became the recommended function. This does't return a FAILURE for - * exceptions and needs to be in a try/catch block in order to clean up - * properly. + * became the recommended function. + * According to zend internals documentation: + * As of PHP 7.1.0, the function_table argument is not used and should + * always be NULL. See for more details: + * https://www.phpinternalsbook.com/php7/internal_types/functions/callables.html */ int zend_result = FAILURE; zend_try { @@ -113,6 +115,15 @@ zval* nr_php_call_user_func(zval* object_ptr, return NULL; } + /* + * For PHP 8+, in the case of exceptions according to: + * https://www.php.net/manual/en/function.call-user-func.php + * Callbacks registered with functions such as call_user_func() and + * call_user_func_array() will not be called if there is an uncaught exception + * thrown in a previous callback. So if we call something that causes an + * exception, it will block us from future calls that use call_user_func or + * call_user_func_array and hence the need for a try/catch block. + */ zend_result = nr_php_call_try_catch(object, method_name, retval, param_count, param_values); #elif ZEND_MODULE_API_NO < ZEND_8_2_X_API_NO \ && ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO diff --git a/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php8.php b/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php8.php index 07266ffa7..299616114 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php8.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_apply_filters.php8.php @@ -52,6 +52,10 @@ function apply_filters($tag, ...$args) { call_user_func_array($tag, $args); } +//Simple mock of wordpress's get_theme_roots +function get_theme_roots() { +} + function h($str) { echo "h: "; echo $str; diff --git a/tests/integration/frameworks/wordpress/test_wordpress_do_action.php8.php b/tests/integration/frameworks/wordpress/test_wordpress_do_action.php8.php index a24492dff..872b87281 100644 --- a/tests/integration/frameworks/wordpress/test_wordpress_do_action.php8.php +++ b/tests/integration/frameworks/wordpress/test_wordpress_do_action.php8.php @@ -52,6 +52,10 @@ function do_action($tag, ...$args) { call_user_func_array($tag, $args); } +//Simple mock of wordpress's get_theme_roots +function get_theme_roots() { +} + function h() { echo "h\n"; throw new Exception("Test Exception");