Skip to content

Commit 52f56cc

Browse files
committed
fix(agent): Adds 4 parameter version of newrelic_notice_error()
PHP 8+ only pass 4 parameters instead of 5 to a handler configured with set_error_handler(). Since newrelic_notice_error() can be used as an error handler it needs to accept this form as well.
1 parent 393ca93 commit 52f56cc

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

agent/php_api.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,30 @@ void nr_php_api_add_supportability_metric(const char* name TSRMLS_DC) {
5858

5959
/*
6060
* Purpose : (New Relic API) Pretend that there is an error at this exact spot.
61-
* Useful for business logic errors. newrelic_notice_error($errstr)
61+
* Useful for business logic errors.
62+
* - newrelic_notice_error($errstr)
63+
* - $errstr : string : The error message to record
6264
* - newrelic_notice_error($exception)
65+
* - $exception : object : The exception to use to record the exception
66+
* NOTE: This version is compatible with being a callback for set_exception_handler()
6367
* - newrelic_notice_error($errstr,$exception)
68+
* - $errstr : string : The error message to record
69+
* - $exception : object : The exception to use to record the exception
70+
* NOTE: The $errstr value is ignored! Started with agent version 4.23
71+
* - newrelic_notice_error($errno,$errstr,$fname,$line_nr)
72+
* - $errno : int : The error number
73+
* - $errstr : string : The error message
74+
* - $fname : string : The filename where the error occurred
75+
* - $line_nr : int : The line number where the error occurred
76+
* NOTE: This version is compatible with being a callback for set_error_handler() for PHP 8+
6477
* - newrelic_notice_error($errno,$errstr,$fname,$line_nr,$ctx)
78+
* - $errno : int : The error number
79+
* - $errstr : string : The error message
80+
* - $fname : string : The filename where the error occurred
81+
* - $line_nr : int : The line number where the error occurred
82+
* - $ctx : array : The context of the error
83+
* NOTE: This version is compatible with being a callback for set_error_handler() for PHP < 8
84+
* The $ctx is ignored!
6585
*/
6686
#ifdef TAGS
6787
void zif_newrelic_notice_error(void); /* ctags landing pad only */
@@ -141,10 +161,15 @@ PHP_FUNCTION(newrelic_notice_error) {
141161
}
142162
break;
143163

164+
case 4:
144165
case 5:
166+
/* PHP 8+ will only pass the first 4 parameters so the 5th parameter is
167+
* declared to be optional. Also this parameter is completely ignored
168+
* so it doesn't matter if it is passed or not.
169+
*/
145170
if (FAILURE
146171
== zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
147-
ZEND_NUM_ARGS() TSRMLS_CC, "lsslz!",
172+
ZEND_NUM_ARGS() TSRMLS_CC, "lssl|z!",
148173
&ignore1, &errormsgstr, &errormsglen,
149174
&ignore2, &ignore3, &ignore4, &ignore5)) {
150175
nrl_debug(NRL_API, "newrelic_notice_error: invalid five arguments");
@@ -153,7 +178,7 @@ PHP_FUNCTION(newrelic_notice_error) {
153178
break;
154179

155180
default:
156-
nrl_debug(NRL_API, "newrelic_notice_error: invalid number of arguments");
181+
nrl_debug(NRL_API, "newrelic_notice_error: invalid number of arguments: %d", ZEND_NUM_ARGS());
157182
RETURN_NULL();
158183
}
159184

0 commit comments

Comments
 (0)