mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-07-25 08:11:22 +02:00
Add support for finally clauses (PHP 5.5)
This adds a new finallyStmts subnode to the TryCatch node. If there is no finally clause it will be null.
This commit is contained in:
@@ -1,16 +1,92 @@
|
||||
Try/catch
|
||||
-----
|
||||
<?php
|
||||
|
||||
try {
|
||||
|
||||
doTry();
|
||||
} catch (A $b) {
|
||||
|
||||
doCatchA();
|
||||
} catch (B $c) {
|
||||
|
||||
doCatchB();
|
||||
} finally {
|
||||
doFinally();
|
||||
}
|
||||
|
||||
// no finally
|
||||
try { }
|
||||
catch (A $b) { }
|
||||
|
||||
// no catch
|
||||
try { }
|
||||
finally { }
|
||||
|
||||
-----
|
||||
array(
|
||||
0: Stmt_TryCatch(
|
||||
stmts: array(
|
||||
0: Expr_FuncCall(
|
||||
name: Name(
|
||||
parts: array(
|
||||
0: doTry
|
||||
)
|
||||
)
|
||||
args: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
catches: array(
|
||||
0: Stmt_Catch(
|
||||
type: Name(
|
||||
parts: array(
|
||||
0: A
|
||||
)
|
||||
)
|
||||
var: b
|
||||
stmts: array(
|
||||
0: Expr_FuncCall(
|
||||
name: Name(
|
||||
parts: array(
|
||||
0: doCatchA
|
||||
)
|
||||
)
|
||||
args: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
1: Stmt_Catch(
|
||||
type: Name(
|
||||
parts: array(
|
||||
0: B
|
||||
)
|
||||
)
|
||||
var: c
|
||||
stmts: array(
|
||||
0: Expr_FuncCall(
|
||||
name: Name(
|
||||
parts: array(
|
||||
0: doCatchB
|
||||
)
|
||||
)
|
||||
args: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
finallyStmts: array(
|
||||
0: Expr_FuncCall(
|
||||
name: Name(
|
||||
parts: array(
|
||||
0: doFinally
|
||||
)
|
||||
)
|
||||
args: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
1: Stmt_TryCatch(
|
||||
stmts: array(
|
||||
)
|
||||
catches: array(
|
||||
@@ -24,16 +100,15 @@ array(
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
1: Stmt_Catch(
|
||||
type: Name(
|
||||
parts: array(
|
||||
0: B
|
||||
)
|
||||
)
|
||||
var: c
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
finallyStmts: null
|
||||
)
|
||||
2: Stmt_TryCatch(
|
||||
stmts: array(
|
||||
)
|
||||
catches: array(
|
||||
)
|
||||
finallyStmts: array(
|
||||
)
|
||||
)
|
||||
)
|
7
test/code/parser/stmt/tryCatch.test-fail
Normal file
7
test/code/parser/stmt/tryCatch.test-fail
Normal file
@@ -0,0 +1,7 @@
|
||||
Cannot use try without catch or finally
|
||||
-----
|
||||
<?php
|
||||
|
||||
try { }
|
||||
-----
|
||||
Cannot use try without catch or finally on line 3
|
Reference in New Issue
Block a user