diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-11 09:40:19 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-11 09:41:19 +0100 |
commit | d80d918547b676e78ccf096a24069a8b2e5dd96b (patch) | |
tree | 8d4af3aa0a5e5399058a5d710a9a8ab518232749 | |
parent | 39c6aaa9ccf9ab02a28c41b6dc931f91fb19a563 (diff) | |
download | php-git-d80d918547b676e78ccf096a24069a8b2e5dd96b.tar.gz |
Don't throw additional Error in require_once if exception already thrown
As pointed out in comments on bug #66216.
-rw-r--r-- | Zend/tests/require_once_warning_to_exception.phpt | 19 | ||||
-rw-r--r-- | Zend/zend_execute.c | 2 |
2 files changed, 20 insertions, 1 deletions
diff --git a/Zend/tests/require_once_warning_to_exception.phpt b/Zend/tests/require_once_warning_to_exception.phpt new file mode 100644 index 0000000000..d115ac68cc --- /dev/null +++ b/Zend/tests/require_once_warning_to_exception.phpt @@ -0,0 +1,19 @@ +--TEST-- +Promoting require_once warning to exception +--FILE-- +<?php + +function exception_error_handler($errno, $errstr, $errfile, $errline ) { + throw new Exception($errstr); +} +set_error_handler("exception_error_handler"); + +try { + $results = require_once 'does-not-exist.php'; +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +}; + +?> +--EXPECT-- +require_once(does-not-exist.php): Failed to open stream: No such file or directory diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index ca1f88ba55..bc964c1ad1 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -4224,7 +4224,7 @@ static zend_never_inline zend_op_array* ZEND_FASTCALL zend_include_or_eval(zval already_compiled: new_op_array = ZEND_FAKE_OP_ARRAY; } - } else { + } else if (!EG(exception)) { zend_message_dispatcher( (type == ZEND_INCLUDE_ONCE) ? ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN, |