Skip to content

fix: disallow using multiple throw expressions #18512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
12 changes: 12 additions & 0 deletions Zend/tests/throw/throw_throw_throw.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
throw throw guard
--FILE--
<?php

try {
throw throw new Exception;
} catch (Exception $e) {
}
?>
--EXPECTF--
Fatal error: Cannot throw throw expression in %s on line %d
4 changes: 4 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5746,6 +5746,10 @@ static void zend_compile_throw(znode *result, zend_ast *ast) /* {{{ */
{
zend_ast *expr_ast = ast->child[0];

if (expr_ast->kind == ZEND_AST_THROW) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot throw throw expression");
}

znode expr_node;
zend_compile_expr(&expr_node, expr_ast);

Expand Down