From 11408fa65e07f31363b4669e97f5f7d10f39e801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 28 Jan 2025 21:16:54 +0100 Subject: [PATCH] Enable userland error handler when compiling in OPcache --- ext/opcache/ZendAccelerator.c | 4 --- ext/opcache/tests/gh17422/001.phpt | 32 +++++++++++++++++++++++ ext/opcache/tests/gh17422/002.phpt | 36 ++++++++++++++++++++++++++ ext/opcache/tests/gh17422/003.phpt | 30 +++++++++++++++++++++ ext/opcache/tests/gh17422/004.phpt | 36 ++++++++++++++++++++++++++ ext/opcache/tests/gh17422/005.phpt | 34 ++++++++++++++++++++++++ ext/opcache/tests/gh17422/dummy.inc | 4 +++ ext/opcache/tests/gh17422/shutdown.inc | 6 +++++ ext/opcache/tests/gh17422/warning.inc | 8 ++++++ 9 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 ext/opcache/tests/gh17422/001.phpt create mode 100644 ext/opcache/tests/gh17422/002.phpt create mode 100644 ext/opcache/tests/gh17422/003.phpt create mode 100644 ext/opcache/tests/gh17422/004.phpt create mode 100644 ext/opcache/tests/gh17422/005.phpt create mode 100644 ext/opcache/tests/gh17422/dummy.inc create mode 100644 ext/opcache/tests/gh17422/shutdown.inc create mode 100644 ext/opcache/tests/gh17422/warning.inc diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index a71a512c03edd..265aeda308ed1 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1728,7 +1728,6 @@ static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handl zend_persistent_script *new_persistent_script; uint32_t orig_functions_count, orig_class_count; zend_op_array *orig_active_op_array; - zval orig_user_error_handler; zend_op_array *op_array; bool do_bailout = false; accel_time_t timestamp = 0; @@ -1796,10 +1795,8 @@ static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handl orig_active_op_array = CG(active_op_array); orig_functions_count = EG(function_table)->nNumUsed; orig_class_count = EG(class_table)->nNumUsed; - ZVAL_COPY_VALUE(&orig_user_error_handler, &EG(user_error_handler)); /* Override them with ours */ - ZVAL_UNDEF(&EG(user_error_handler)); if (ZCG(accel_directives).record_warnings) { zend_begin_record_errors(); } @@ -1825,7 +1822,6 @@ static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handl /* Restore originals */ CG(active_op_array) = orig_active_op_array; - EG(user_error_handler) = orig_user_error_handler; EG(record_errors) = 0; if (!op_array) { diff --git a/ext/opcache/tests/gh17422/001.phpt b/ext/opcache/tests/gh17422/001.phpt new file mode 100644 index 0000000000000..f8bc8ca12896f --- /dev/null +++ b/ext/opcache/tests/gh17422/001.phpt @@ -0,0 +1,32 @@ +--TEST-- +GH-17422 (OPcache bypasses the user-defined error handler for deprecations) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +--EXTENSIONS-- +opcache +--FILE-- + +--EXPECT-- +set_error_handler: "continue" targeting switch is equivalent to "break" +OK: warning +array(3) { + [0]=> + string(7) "001.php" + [1]=> + string(12) "shutdown.inc" + [2]=> + string(11) "warning.inc" +} diff --git a/ext/opcache/tests/gh17422/002.phpt b/ext/opcache/tests/gh17422/002.phpt new file mode 100644 index 0000000000000..1fc8af33b92a0 --- /dev/null +++ b/ext/opcache/tests/gh17422/002.phpt @@ -0,0 +1,36 @@ +--TEST-- +GH-17422 (OPcache bypasses the user-defined error handler for deprecations) - Throwing error handler +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +--EXTENSIONS-- +opcache +--FILE-- +getMessage(), PHP_EOL; +} + +warning(); + +?> +--EXPECT-- +Caught: "continue" targeting switch is equivalent to "break" +OK: warning +array(3) { + [0]=> + string(7) "002.php" + [1]=> + string(12) "shutdown.inc" + [2]=> + string(11) "warning.inc" +} diff --git a/ext/opcache/tests/gh17422/003.phpt b/ext/opcache/tests/gh17422/003.phpt new file mode 100644 index 0000000000000..6862579d3563b --- /dev/null +++ b/ext/opcache/tests/gh17422/003.phpt @@ -0,0 +1,30 @@ +--TEST-- +GH-17422 (OPcache bypasses the user-defined error handler for deprecations) - Fatal Error +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +memory_limit=2M +--EXTENSIONS-- +opcache +--FILE-- + +--EXPECTF-- +Fatal error: Allowed memory size of 2097152 bytes exhausted %s on line 6 +array(2) { + [0]=> + string(7) "003.php" + [1]=> + string(12) "shutdown.inc" +} diff --git a/ext/opcache/tests/gh17422/004.phpt b/ext/opcache/tests/gh17422/004.phpt new file mode 100644 index 0000000000000..30d0d32a70d26 --- /dev/null +++ b/ext/opcache/tests/gh17422/004.phpt @@ -0,0 +1,36 @@ +--TEST-- +GH-17422 (OPcache bypasses the user-defined error handler for deprecations) - eval +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +memory_limit=2M +--EXTENSIONS-- +opcache +--FILE-- + +--EXPECTF-- +Fatal error: Cannot redeclare function warning() (previously declared in %s(8) : eval()'d code:1) in %swarning.inc on line 2 +array(2) { + [0]=> + string(7) "004.php" + [1]=> + string(12) "shutdown.inc" +} diff --git a/ext/opcache/tests/gh17422/005.phpt b/ext/opcache/tests/gh17422/005.phpt new file mode 100644 index 0000000000000..a22461d889205 --- /dev/null +++ b/ext/opcache/tests/gh17422/005.phpt @@ -0,0 +1,34 @@ +--TEST-- +GH-17422 (OPcache bypasses the user-defined error handler for deprecations) - require +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +memory_limit=2M +--EXTENSIONS-- +opcache +--FILE-- + +--EXPECT-- +OK: dummy +array(4) { + [0]=> + string(7) "005.php" + [1]=> + string(9) "dummy.inc" + [2]=> + string(12) "shutdown.inc" + [3]=> + string(11) "warning.inc" +} diff --git a/ext/opcache/tests/gh17422/dummy.inc b/ext/opcache/tests/gh17422/dummy.inc new file mode 100644 index 0000000000000..0bb253556124a --- /dev/null +++ b/ext/opcache/tests/gh17422/dummy.inc @@ -0,0 +1,4 @@ +