From 0afc8ef76438de231419d413da75b9617defb6c2 Mon Sep 17 00:00:00 2001 From: Joost Waaijer Date: Fri, 21 Aug 2026 08:21:34 +0200 Subject: [PATCH 1/2] Fixed GH-22727: Attribute return opcodes to return statement --- NEWS | 2 ++ Zend/tests/gh22727.phpt | 21 +++++++++++++++++++++ Zend/zend_compile.c | 3 +++ 3 files changed, 26 insertions(+) create mode 100644 Zend/tests/gh22727.phpt diff --git a/NEWS b/NEWS index 86b6bd3e2e0c..5e9f92701439 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP NEWS - Core: . Fixed bug GH-15375 (Nested "yield from" skips items after a valid() or next() call on the inner generator). (iliaal) + . Fixed bug GH-22727 (RETURN opcodes for multiline expressions use the wrong + line). (Joost Waaijer) . Fixed bug GH-23301 (Nested "yield from" yields a value twice when the middle generator delegates again). (Lazizbek Ergashev) diff --git a/Zend/tests/gh22727.phpt b/Zend/tests/gh22727.phpt new file mode 100644 index 000000000000..0aafd5ff938f --- /dev/null +++ b/Zend/tests/gh22727.phpt @@ -0,0 +1,21 @@ +--TEST-- +GH-22727: Return opcodes use the return statement line for multiline expressions +--FILE-- + 'not an int', + }; +} + +try { + test(); +} catch (TypeError $exception) { + echo $exception->getLine(), "\n"; +} + +?> +--EXPECT-- +5 diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 42c136d6bf36..0e493f098eca 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5687,6 +5687,7 @@ static bool zend_has_finally(void) /* {{{ */ static void zend_compile_return(zend_ast *ast) /* {{{ */ { zend_ast *expr_ast = ast->child[0]; + uint32_t return_lineno = CG(zend_lineno); bool is_generator = (CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR) != 0; bool by_ref = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0; @@ -5708,6 +5709,8 @@ static void zend_compile_return(zend_ast *ast) /* {{{ */ zend_compile_expr(&expr_node, expr_ast); } + CG(zend_lineno) = return_lineno; + 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()) { From 8700667f297e381c5d7a4957d7c769fe7033936c Mon Sep 17 00:00:00 2001 From: Joost Waaijer Date: Sat, 22 Aug 2026 09:35:02 +0200 Subject: [PATCH 2/2] Update gh22727.phpt Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com> --- Zend/tests/gh22727.phpt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Zend/tests/gh22727.phpt b/Zend/tests/gh22727.phpt index 0aafd5ff938f..a65ea727dee9 100644 --- a/Zend/tests/gh22727.phpt +++ b/Zend/tests/gh22727.phpt @@ -12,10 +12,10 @@ function test(): int try { test(); -} catch (TypeError $exception) { - echo $exception->getLine(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': on line ', $e->getLine(), "\n"; } ?> --EXPECT-- -5 +TypeError: on line 5