Skip to content

Commit 7aa56f8

Browse files
committed
Gate new error func arg display behind display_error_function_args
This is a useful feature, but enabling it by default requires rewriting every PHPT file's output section. Since that would be a hellish diff to make and to review, I think the best option is unfortunately, another INI option. We can enable this for prod/dev recommended INIs, but make sure it's disabled for the test runner. This takes some inspiration from the discussion in GH-17056, which has similar problems to this PR.
1 parent d6b038d commit 7aa56f8

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

main/main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ PHP_INI_BEGIN()
801801

802802
STD_PHP_INI_ENTRY_EX("display_errors", "1", PHP_INI_ALL, OnUpdateDisplayErrors, display_errors, php_core_globals, core_globals, display_errors_mode)
803803
STD_PHP_INI_BOOLEAN("display_startup_errors", "1", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals)
804+
STD_PHP_INI_BOOLEAN("display_error_function_args", "0", PHP_INI_ALL, OnUpdateBool, display_error_function_args, php_core_globals, core_globals)
804805
STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals)
805806
STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals)
806807
STD_PHP_INI_ENTRY("docref_root", "", PHP_INI_ALL, OnUpdateString, docref_root, php_core_globals, core_globals)
@@ -1134,7 +1135,9 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ
11341135
/* if we still have memory then format the origin */
11351136
if (is_function) {
11361137
zend_string *dynamic_params = NULL;
1137-
dynamic_params = zend_trace_current_function_args_string();
1138+
if (PG(display_error_function_args)) {
1139+
dynamic_params = zend_trace_current_function_args_string();
1140+
}
11381141
origin_len = spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, dynamic_params ? ZSTR_VAL(dynamic_params) : params);
11391142
if (dynamic_params) {
11401143
zend_string_release(dynamic_params);

main/php_globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct _php_core_globals {
5959

6060
uint8_t display_errors;
6161
bool display_startup_errors;
62+
bool display_error_function_args;
6263
bool log_errors;
6364
bool ignore_repeated_errors;
6465
bool ignore_repeated_source;

php.ini-development

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,15 @@ ignore_repeated_source = Off
611611
; Production Value: On
612612
;fatal_error_backtraces = On
613613

614+
; This directive controls whether PHP will print the actual arguments of a
615+
; function upon an error. If disabled (or there was an error fetching the
616+
; arguments), the function providing the error may optionally provide some
617+
; additional information after the problem function's name.
618+
; Default Value: Off
619+
; Development Value: On
620+
; Production Value: On
621+
display_error_function_args = On
622+
614623
;;;;;;;;;;;;;;;;;
615624
; Data Handling ;
616625
;;;;;;;;;;;;;;;;;

php.ini-production

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,15 @@ ignore_repeated_source = Off
613613
; Production Value: On
614614
;fatal_error_backtraces = On
615615

616+
; This directive controls whether PHP will print the actual arguments of a
617+
; function upon an error. If disabled (or there was an error fetching the
618+
; arguments), the function providing the error may optionally provide some
619+
; additional information after the problem function's name.
620+
; Default Value: Off
621+
; Development Value: On
622+
; Production Value: On
623+
display_error_function_args = On
624+
616625
;;;;;;;;;;;;;;;;;
617626
; Data Handling ;
618627
;;;;;;;;;;;;;;;;;

run-tests.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ function main(): void
273273
'fatal_error_backtraces=Off',
274274
'display_errors=1',
275275
'display_startup_errors=1',
276+
'display_error_function_args=0',
276277
'log_errors=0',
277278
'html_errors=0',
278279
'track_errors=0',

0 commit comments

Comments
 (0)