diff options
Diffstat (limited to 'Zend')
| -rw-r--r-- | Zend/tests/bug60909_1.phpt | 4 | ||||
| -rw-r--r-- | Zend/tests/exception_during_include_stat.phpt | 41 | ||||
| -rw-r--r-- | Zend/zend_execute.c | 2 | ||||
| -rw-r--r-- | Zend/zend_language_scanner.l | 12 |
4 files changed, 51 insertions, 8 deletions
diff --git a/Zend/tests/bug60909_1.phpt b/Zend/tests/bug60909_1.phpt index e4c07face1..c82cf6c4d5 100644 --- a/Zend/tests/bug60909_1.phpt +++ b/Zend/tests/bug60909_1.phpt @@ -11,14 +11,12 @@ set_error_handler(function($errno, $errstr, $errfile, $errline){ require 'notfound.php'; --EXPECTF-- error(require(notfound.php): failed to open stream: %s) -Warning: Uncaught Exception: Foo in %sbug60909_1.php:5 +Fatal error: Uncaught Exception: Foo in %sbug60909_1.php:5 Stack trace: #0 %sbug60909_1.php(8): {closure}(2, 'require(notfoun...', '%s', 8, Array) #1 %sbug60909_1.php(8): require() #2 {main} thrown in %sbug60909_1.php on line 5 -Fatal error: main(): Failed opening required 'notfound.php' (include_path='%s') in %sbug60909_1.php on line 8 - !!!shutdown!!! diff --git a/Zend/tests/exception_during_include_stat.phpt b/Zend/tests/exception_during_include_stat.phpt new file mode 100644 index 0000000000..1927e7e251 --- /dev/null +++ b/Zend/tests/exception_during_include_stat.phpt @@ -0,0 +1,41 @@ +--TEST-- +Make sure exceptions during include/require stating are properly propagated +--FILE-- +<?php + +class StreamWrapper { + public function url_stat($path, $flags) { + throw new Exception('stat failed'); + } +} + +stream_wrapper_register('test', StreamWrapper::class); +set_include_path('test://foo:test://bar'); + +try { + require_once 'doesnt_exist.php'; +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +} +try { + require 'doesnt_exist.php'; +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +} +try { + include_once 'doesnt_exist.php'; +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +} +try { + include 'doesnt_exist.php'; +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +stat failed +stat failed +stat failed +stat failed diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 9ae73caae1..ab0d3656ee 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -4192,6 +4192,8 @@ static zend_never_inline zend_op_array* ZEND_FASTCALL zend_include_or_eval(zval if (zend_hash_exists(&EG(included_files), resolved_path)) { goto already_compiled; } + } else if (UNEXPECTED(EG(exception))) { + break; } else if (UNEXPECTED(strlen(Z_STRVAL_P(inc_filename)) != Z_STRLEN_P(inc_filename))) { zend_message_dispatcher( (type == ZEND_INCLUDE_ONCE) ? diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 7dcb4dfcee..412356cdc1 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -637,11 +637,13 @@ ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type) zend_save_lexical_state(&original_lex_state); if (open_file_for_scanning(file_handle)==FAILURE) { - if (type==ZEND_REQUIRE) { - zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename); - zend_bailout(); - } else { - zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename); + if (!EG(exception)) { + if (type==ZEND_REQUIRE) { + zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename); + zend_bailout(); + } else { + zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename); + } } } else { op_array = zend_compile(ZEND_USER_FUNCTION); |
