Skip to content

Commit

Permalink
additional context from PR #638
Browse files Browse the repository at this point in the history
  • Loading branch information
ZNeumann committed Aug 3, 2023
1 parent 2646560 commit 91388e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions agent/php_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 91388e3

Please sign in to comment.