Skip to content

Commit 73fad28

Browse files
committed
Add test
1 parent a1f0b7a commit 73fad28

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

Zend/tests/exception-coalesce.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
??? - basic test for exception coalesce operator
3+
--FILE--
4+
<?php
5+
echo "php" ??? "php is real\n";
6+
echo foo() ??? "foo() does not exist\n";
7+
8+
function bar() { throw new Exception("bar"); }
9+
echo bar() ??? "user generated exception\n";
10+
11+
function baz() { return "all ok"; }
12+
echo baz() ??? "something is wrong here";
13+
?>
14+
--EXPECT--
15+
php is real
16+
foo() does not exist
17+
user generated exception
18+
all ok

Zend/zend_compile.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ static void zend_mark_function_as_generator() /* {{{ */
12781278

12791279
if (ZEND_TYPE_CODE(return_info.type) != IS_ITERABLE) {
12801280
const char *msg = "Generators may only declare a return type of Generator, Iterator, Traversable, or iterable, %s is not permitted";
1281-
1281+
12821282
if (!ZEND_TYPE_IS_CLASS(return_info.type)) {
12831283
zend_error_noreturn(E_COMPILE_ERROR, msg, zend_get_type_by_const(ZEND_TYPE_CODE(return_info.type)));
12841284
}
@@ -1947,7 +1947,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
19471947
static void zend_adjust_for_fetch_type(zend_op *opline, uint32_t type) /* {{{ */
19481948
{
19491949
zend_uchar factor = (opline->opcode == ZEND_FETCH_STATIC_PROP_R) ? 1 : 3;
1950-
1950+
19511951
if (opline->opcode == ZEND_FETCH_THIS) {
19521952
return;
19531953
}
@@ -2185,7 +2185,7 @@ static void zend_emit_tick(void) /* {{{ */
21852185
if (CG(active_op_array)->last && CG(active_op_array)->opcodes[CG(active_op_array)->last - 1].opcode == ZEND_TICKS) {
21862186
return;
21872187
}
2188-
2188+
21892189
opline = get_next_op(CG(active_op_array));
21902190

21912191
opline->opcode = ZEND_TICKS;
@@ -2612,7 +2612,7 @@ static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint
26122612
opline = zend_emit_op(result, ZEND_FETCH_R, &name_node, NULL);
26132613
}
26142614

2615-
if (name_node.op_type == IS_CONST &&
2615+
if (name_node.op_type == IS_CONST &&
26162616
zend_is_auto_global(Z_STR(name_node.u.constant))) {
26172617

26182618
opline->extended_value = ZEND_FETCH_GLOBAL;
@@ -4968,7 +4968,7 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */
49684968
} else if (expr_node.op_type == IS_CONST
49694969
&& Z_TYPE(expr_node.u.constant) == IS_TRUE) {
49704970
jmpnz_opnums[i] = zend_emit_cond_jump(ZEND_JMPNZ, &cond_node, 0);
4971-
} else {
4971+
} else {
49724972
opline = zend_emit_op(NULL, ZEND_CASE, &expr_node, &cond_node);
49734973
SET_NODE(opline->result, &case_node);
49744974
if (opline->op1_type == IS_CONST) {
@@ -4992,7 +4992,7 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */
49924992
if (jumptable) {
49934993
zval *cond_zv = zend_ast_get_zval(cond_ast);
49944994
zval jmp_target;
4995-
ZVAL_LONG(&jmp_target, get_next_op_number(CG(active_op_array)));
4995+
ZVAL_LONG(&jmp_target, get_next_op_number(CG(active_op_array)));
49964996

49974997
ZEND_ASSERT(Z_TYPE_P(cond_zv) == jumptable_type);
49984998
if (Z_TYPE_P(cond_zv) == IS_LONG) {
@@ -5166,7 +5166,7 @@ void zend_compile_try(zend_ast *ast) /* {{{ */
51665166
if (finally_ast) {
51675167
zend_loop_var discard_exception;
51685168
uint32_t opnum_jmp = get_next_op_number(CG(active_op_array)) + 1;
5169-
5169+
51705170
/* Pop FAST_CALL from unwind stack */
51715171
zend_stack_del_top(&CG(loop_var_stack));
51725172

@@ -5417,7 +5417,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
54175417
uint32_t i;
54185418
zend_op_array *op_array = CG(active_op_array);
54195419
zend_arg_info *arg_infos;
5420-
5420+
54215421
if (return_type_ast) {
54225422
zend_bool allow_null = 0;
54235423

@@ -5560,7 +5560,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
55605560
"with a float type can only be float, integer, or NULL");
55615561
}
55625562
break;
5563-
5563+
55645564
case IS_ITERABLE:
55655565
if (Z_TYPE(default_node.u.constant) != IS_ARRAY) {
55665566
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
@@ -5572,7 +5572,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
55725572
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
55735573
"with an object type can only be NULL");
55745574
break;
5575-
5575+
55765576
default:
55775577
if (!ZEND_SAME_FAKE_TYPE(ZEND_TYPE_CODE(arg_info->type), Z_TYPE(default_node.u.constant))) {
55785578
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
@@ -5605,7 +5605,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
56055605
} else {
56065606
opline->op2.num = -1;
56075607
}
5608-
}
5608+
}
56095609
}
56105610

56115611
/* These are assigned at the end to avoid unitialized memory in case of an error */
@@ -7315,12 +7315,11 @@ void zend_compile_coalesce(znode *result, zend_ast *ast) /* {{{ */
73157315

73167316
void zend_compile_exception_coalesce(znode *result, zend_ast *ast) /* {{{ */
73177317
{
7318-
zend_ast *expr_ast = ast->child[0];
7319-
zend_ast *default_ast = ast->child[1];
7318+
zend_ast *expr = ast->child[0];
73207319

73217320
zend_ast *hack = zend_ast_create_ex(ZEND_AST_INCLUDE_OR_EVAL, ZEND_EVAL,
73227321
zend_ast_create_zval_from_str(
7323-
zend_ast_export("try { return ", expr_ast, "; } catch(\\Throwable $e) {}")));
7322+
zend_ast_export("try { return ", expr, "; } catch(\\Throwable $e) {}")));
73247323

73257324
ast->child[0] = hack;
73267325

@@ -7871,7 +7870,7 @@ static void zend_compile_encaps_list(znode *result, zend_ast *ast) /* {{{ */
78717870
i = ((j * sizeof(zend_string*)) + (sizeof(zval) - 1)) / sizeof(zval);
78727871
while (i > 1) {
78737872
get_temporary_variable(CG(active_op_array));
7874-
i--;
7873+
i--;
78757874
}
78767875

78777876
zend_end_live_range(CG(active_op_array), range, opline - CG(active_op_array)->opcodes,

0 commit comments

Comments
 (0)