Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Zend/tests/exit_finally_3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ function test() {
var_dump(test());

?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
Exit
3 changes: 2 additions & 1 deletion Zend/tests/gc/gc_050.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ for ($i = 0; $i < 100000; $i++) {
}
echo "OK\n";
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
OK
3 changes: 2 additions & 1 deletion Zend/tests/generators/finally/return_return.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ $gen = gen();
$gen->rewind(); // force run

?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
before return
before return in inner finally
outer finally run
3 changes: 2 additions & 1 deletion Zend/tests/generators/finally/yield_return.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ foreach (foo(1, 5) as $x) {
echo $x, "\n";
}
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
1
3 changes: 2 additions & 1 deletion Zend/tests/generators/get_return_and_finally.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ try {
}

?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
int(42)
gen2() throw
Cannot get return value of a generator that hasn't returned
3 changes: 2 additions & 1 deletion Zend/tests/generators/gh11028_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ test("false", false);
test("true", true);
test("object", new stdClass);
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
yield null
Keys must be of type int|string during array unpacking
yield false
Expand Down
2 changes: 2 additions & 0 deletions Zend/tests/generators/gh11028_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ $c = (function () {
})()[0];
?>
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d

Warning: Undefined variable $a in %s on line %d

Fatal error: Uncaught Error: Keys must be of type int|string during array unpacking in %s:%d
Expand Down
3 changes: 2 additions & 1 deletion Zend/tests/generators/gh11028_3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ try {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
exception
3 changes: 2 additions & 1 deletion Zend/tests/generators/yield_in_finally_cleanup.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ gen4()->rewind();

?>
===DONE===
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
===DONE===
2 changes: 2 additions & 0 deletions Zend/tests/oss_fuzz_438780145.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ test();

?>
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d

Fatal error: Uncaught TypeError: test(): Return value must be of type int, string returned in %s:%d
Stack trace:
#0 %s(%d): test()
Expand Down
2 changes: 2 additions & 0 deletions Zend/tests/return_types/029.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function foo() : array {
foo();
?>
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d

Fatal error: Uncaught Exception: xxxx in %s:%d
Stack trace:
#0 %s(%d): foo()
Expand Down
2 changes: 2 additions & 0 deletions Zend/tests/return_types/never_finally_return.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ function foo() : never {
// Note the lack of function call: function validated at compile-time
?>
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d

Fatal error: A never-returning function must not return in %s on line %d
3 changes: 2 additions & 1 deletion Zend/tests/try/bug70228.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ function foo() {

var_dump(foo());
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
string(2) "bb"
3 changes: 2 additions & 1 deletion Zend/tests/try/bug70228_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ function test() {

var_dump(test());
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
int(42)
3 changes: 2 additions & 1 deletion Zend/tests/try/bug70228_3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ try {
} while ($e);
}
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
2
1
3 changes: 2 additions & 1 deletion Zend/tests/try/bug70228_4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ try {
} while ($e);
}
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
1
3 changes: 2 additions & 1 deletion Zend/tests/try/bug70228_6.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ function test($x) {

var_dump(test([1]));
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
int(42)
5 changes: 4 additions & 1 deletion Zend/tests/try/catch_finally_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ function &bar($a) {
var_dump(foo("para"));
var_dump(bar("para"));
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d

Deprecated: Returning from a finally block is deprecated in %s on line %d
string(3) "try"
string(7) "finally"
string(7) "finally"
Expand Down
3 changes: 2 additions & 1 deletion Zend/tests/try/catch_finally_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ function foo ($a) {

var_dump(foo("para"));
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
int(3)
3 changes: 2 additions & 1 deletion Zend/tests/try/catch_finally_006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ try {
var_dump($e->getMessage());
}
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
string(4) "para"
string(7) "finally"
string(6) "return"
3 changes: 2 additions & 1 deletion Zend/tests/try/finally_goto_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ label: try {
}

?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
success
86 changes: 86 additions & 0 deletions Zend/tests/try/finally_return_deprecation.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
--TEST--
Returning from a finally block is deprecated
--FILE--
<?php

function withValue() {
try {
} finally {
return 1;
}
}

function withoutValue() {
try {
} finally {
return;
}
}

// Not deprecated: the return belongs to the try block, not the finally.
function inTry() {
try {
return 1;
} finally {
}
}

// Not deprecated: the return belongs to a catch block.
function inCatch() {
try {
throw new Exception();
} catch (Exception $e) {
return 1;
} finally {
}
}

// Not deprecated: the return belongs to a nested closure, not the finally.
function nestedClosure() {
try {
} finally {
$f = function () {
return 1;
};
}
}

// Deprecated twice: both returns are lexically inside the outer finally, even
// though one of them sits in a nested try block.
function nestedTry() {
try {
} finally {
try {
return 1;
} finally {
return 2;
}
}
}

// Deprecated once: only the closure's own finally return is flagged. The outer
// finally must not leak into the closure, so the closure's try return is left alone.
function closureWithTry() {
try {
} finally {
$f = function () {
try {
return 1;
} finally {
return 2;
}
};
}
}

?>
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d

Deprecated: Returning from a finally block is deprecated in %s on line %d

Deprecated: Returning from a finally block is deprecated in %s on line %d

Deprecated: Returning from a finally block is deprecated in %s on line %d

Deprecated: Returning from a finally block is deprecated in %s on line %d
3 changes: 2 additions & 1 deletion Zend/tests/try/try_catch_finally_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ function foo () {

var_dump(foo());
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
1234int(4)
3 changes: 2 additions & 1 deletion Zend/tests/try/try_finally_013.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function foo() {

foo();
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
try
finally
3 changes: 2 additions & 1 deletion Zend/tests/try/try_finally_014.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function foo() {

foo();
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
try
finally
3 changes: 2 additions & 1 deletion Zend/tests/try/try_finally_021.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ foreach ([0] as $_) {
}
}
?>
--EXPECT--
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
ok
ok
1 change: 1 addition & 0 deletions Zend/tests/try/try_finally_023.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ try {

?>
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
Exception: 1 in %s:%d
Stack trace:
#0 %s(%d): test()
Expand Down
1 change: 1 addition & 0 deletions Zend/tests/try/try_finally_027.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ try {

?>
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
Exception: 1 in %s:%d
Stack trace:
#0 %s(%d): test()
Expand Down
8 changes: 8 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ void zend_oparray_context_begin(zend_oparray_context *prev_context, zend_op_arra
CG(context).brk_cont_array = NULL;
CG(context).labels = NULL;
CG(context).in_jmp_frameless_branch = false;
CG(context).in_finally = false;
CG(context).active_property_info_name = NULL;
CG(context).active_property_hook_kind = (zend_property_hook_kind)-1;
}
Expand Down Expand Up @@ -6150,6 +6151,10 @@ static void zend_compile_return(const zend_ast *ast) /* {{{ */
}
}

if (CG(context).in_finally) {
zend_error(E_DEPRECATED, "Returning from a finally block is deprecated");
}

if ((CG(active_op_array)->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)
&& (expr_node.op_type == IS_CV || (by_ref && expr_node.op_type == IS_VAR))
&& zend_has_finally()) {
Expand Down Expand Up @@ -7398,7 +7403,10 @@ static void zend_compile_try(const zend_ast *ast) /* {{{ */

zend_emit_op(NULL, ZEND_JMP, NULL, NULL);

bool orig_in_finally = CG(context).in_finally;
CG(context).in_finally = true;
zend_compile_stmt(finally_ast);
CG(context).in_finally = orig_in_finally;

CG(active_op_array)->try_catch_array[try_catch_offset].finally_op = opnum_jmp + 1;
CG(active_op_array)->try_catch_array[try_catch_offset].finally_end
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ typedef struct _zend_oparray_context {
zend_string *active_property_info_name;
zend_property_hook_kind active_property_hook_kind;
bool in_jmp_frameless_branch;
bool in_finally;
bool has_assigned_to_http_response_header;
} zend_oparray_context;

Expand Down
3 changes: 3 additions & 0 deletions sapi/phpdbg/tests/exceptions_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ev 1 + 2
c
q
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
[Successful compilation of %s]
prompt> handle first
[Uncaught Error in %s on line 16: Call to undefined function foo()]
Expand All @@ -22,6 +23,8 @@ Stack trace:
#0 %s(22): {closure:%s:%d}()
#1 {main}
[Script ended normally]

Deprecated: Returning from a finally block is deprecated in %s on line %d
prompt>
--FILE--
<?php
Expand Down
3 changes: 3 additions & 0 deletions sapi/phpdbg/tests/exceptions_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ c

q
--EXPECTF--
Deprecated: Returning from a finally block is deprecated in %s on line %d
[Successful compilation of %s]
prompt> handle first
[Uncaught Error in %s on line 16: Call to undefined function foo()]
Expand All @@ -26,6 +27,8 @@ Stack trace:
#0 %s(20): {closure:%s:%d}()
#1 {main}
[Script ended normally]

Deprecated: Returning from a finally block is deprecated in %s on line %d
prompt> [The stack contains nothing !]
prompt>
--FILE--
Expand Down
Loading