Skip to content

Commit d80d918

Browse files
committed
Don't throw additional Error in require_once if exception already thrown
As pointed out in comments on bug #66216.
1 parent 39c6aaa commit d80d918

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Promoting require_once warning to exception
3+
--FILE--
4+
<?php
5+
6+
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
7+
throw new Exception($errstr);
8+
}
9+
set_error_handler("exception_error_handler");
10+
11+
try {
12+
$results = require_once 'does-not-exist.php';
13+
} catch (Exception $e) {
14+
echo $e->getMessage(), "\n";
15+
};
16+
17+
?>
18+
--EXPECT--
19+
require_once(does-not-exist.php): Failed to open stream: No such file or directory

Zend/zend_execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4224,7 +4224,7 @@ static zend_never_inline zend_op_array* ZEND_FASTCALL zend_include_or_eval(zval
42244224
already_compiled:
42254225
new_op_array = ZEND_FAKE_OP_ARRAY;
42264226
}
4227-
} else {
4227+
} else if (!EG(exception)) {
42284228
zend_message_dispatcher(
42294229
(type == ZEND_INCLUDE_ONCE) ?
42304230
ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN,

0 commit comments

Comments
 (0)