Skip to content

Commit 49396f8

Browse files
committed
Fixed bug #79777
1 parent 344c077 commit 49396f8

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #79777: String cast exception during die should be handled gracefully
3+
--FILE--
4+
<?php
5+
6+
die(new stdClass);
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in %s:%d
11+
Stack trace:
12+
#0 {main}
13+
thrown in %s on line %d

Zend/zend_vm_def.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6893,7 +6893,10 @@ ZEND_VM_COLD_HANDLER(79, ZEND_EXIT, ANY, ANY)
68936893
} while (0);
68946894
FREE_OP1();
68956895
}
6896-
zend_throw_unwind_exit();
6896+
6897+
if (!EG(exception)) {
6898+
zend_throw_unwind_exit();
6899+
}
68976900
HANDLE_EXCEPTION();
68986901
}
68996902

Zend/zend_vm_execute.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,10 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_EXIT_SPEC_HANDLER
23222322
} while (0);
23232323
FREE_OP(opline->op1_type, opline->op1.var);
23242324
}
2325-
zend_throw_unwind_exit();
2325+
2326+
if (!EG(exception)) {
2327+
zend_throw_unwind_exit();
2328+
}
23262329
HANDLE_EXCEPTION();
23272330
}
23282331

@@ -2476,7 +2479,6 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_dispatch_try
24762479
{
24772480
/* May be NULL during generator closing (only finally blocks are executed) */
24782481
zend_object *ex = EG(exception);
2479-
zend_bool is_unwind_exit = ex && zend_is_unwind_exit(ex);
24802482

24812483
/* Walk try/catch/finally structures upwards, performing the necessary actions */
24822484
for (; try_catch_offset != (uint32_t) -1; try_catch_offset--) {
@@ -2489,7 +2491,7 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_dispatch_try
24892491
ZEND_VM_JMP_EX(&EX(func)->op_array.opcodes[try_catch->catch_op], 0);
24902492

24912493
} else if (op_num < try_catch->finally_op) {
2492-
if (is_unwind_exit) {
2494+
if (ex && zend_is_unwind_exit(ex)) {
24932495
/* Don't execute finally blocks on exit (for now) */
24942496
continue;
24952497
}

0 commit comments

Comments
 (0)