]> granicus.if.org Git - php/commitdiff
Don't throw additional Error in require_once if exception already thrown
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 11 Feb 2021 08:40:19 +0000 (09:40 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 11 Feb 2021 08:41:19 +0000 (09:41 +0100)
As pointed out in comments on bug #66216.

Zend/tests/require_once_warning_to_exception.phpt [new file with mode: 0644]
Zend/zend_execute.c

diff --git a/Zend/tests/require_once_warning_to_exception.phpt b/Zend/tests/require_once_warning_to_exception.phpt
new file mode 100644 (file)
index 0000000..d115ac6
--- /dev/null
@@ -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
index ca1f88ba5533f2cb79557633c238816bb4caf227..bc964c1ad160c14d8cf015ae2b2a5f6bad4496dc 100644 (file)
@@ -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,