2011-11-27 11:20:35 +01:00
|
|
|
Ternary operator
|
|
|
|
-----
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// ternary
|
|
|
|
$a ? $b : $c;
|
|
|
|
$a ?: $c;
|
|
|
|
|
|
|
|
// precedence
|
|
|
|
$a ? $b : $c ? $d : $e;
|
|
|
|
$a ? $b : ($c ? $d : $e);
|
2015-03-12 22:45:38 +01:00
|
|
|
|
|
|
|
// null coalesce
|
|
|
|
$a ?? $b;
|
|
|
|
$a ?? $b ?? $c;
|
|
|
|
$a ?? $b ? $c : $d;
|
|
|
|
$a && $b ?? $c;
|
2011-11-27 11:20:35 +01:00
|
|
|
-----
|
|
|
|
array(
|
2017-01-19 22:25:22 +01:00
|
|
|
0: Stmt_Expression(
|
|
|
|
expr: Expr_Ternary(
|
|
|
|
cond: Expr_Variable(
|
|
|
|
name: a
|
|
|
|
comments: array(
|
|
|
|
0: // ternary
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if: Expr_Variable(
|
|
|
|
name: b
|
|
|
|
)
|
|
|
|
else: Expr_Variable(
|
|
|
|
name: c
|
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // ternary
|
|
|
|
)
|
2011-11-27 11:20:35 +01:00
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // ternary
|
|
|
|
)
|
2011-11-27 11:20:35 +01:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
1: Stmt_Expression(
|
|
|
|
expr: Expr_Ternary(
|
2011-11-27 11:20:35 +01:00
|
|
|
cond: Expr_Variable(
|
|
|
|
name: a
|
2017-01-19 22:25:22 +01:00
|
|
|
)
|
|
|
|
if: null
|
|
|
|
else: Expr_Variable(
|
|
|
|
name: c
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
2: Stmt_Expression(
|
|
|
|
expr: Expr_Ternary(
|
|
|
|
cond: Expr_Ternary(
|
|
|
|
cond: Expr_Variable(
|
|
|
|
name: a
|
|
|
|
comments: array(
|
|
|
|
0: // precedence
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if: Expr_Variable(
|
|
|
|
name: b
|
|
|
|
)
|
|
|
|
else: Expr_Variable(
|
|
|
|
name: c
|
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // precedence
|
|
|
|
)
|
2011-11-27 11:20:35 +01:00
|
|
|
)
|
|
|
|
if: Expr_Variable(
|
2017-01-19 22:25:22 +01:00
|
|
|
name: d
|
2011-11-27 11:20:35 +01:00
|
|
|
)
|
|
|
|
else: Expr_Variable(
|
2017-01-19 22:25:22 +01:00
|
|
|
name: e
|
2011-11-27 11:20:35 +01:00
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // precedence
|
|
|
|
)
|
2011-11-27 11:20:35 +01:00
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // precedence
|
|
|
|
)
|
2011-11-27 11:20:35 +01:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
3: Stmt_Expression(
|
|
|
|
expr: Expr_Ternary(
|
2011-11-27 11:20:35 +01:00
|
|
|
cond: Expr_Variable(
|
2017-01-19 22:25:22 +01:00
|
|
|
name: a
|
2011-11-27 11:20:35 +01:00
|
|
|
)
|
|
|
|
if: Expr_Variable(
|
2017-01-19 22:25:22 +01:00
|
|
|
name: b
|
2011-11-27 11:20:35 +01:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
else: Expr_Ternary(
|
|
|
|
cond: Expr_Variable(
|
|
|
|
name: c
|
|
|
|
)
|
|
|
|
if: Expr_Variable(
|
|
|
|
name: d
|
|
|
|
)
|
|
|
|
else: Expr_Variable(
|
|
|
|
name: e
|
|
|
|
)
|
2011-11-27 11:20:35 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
4: Stmt_Expression(
|
|
|
|
expr: Expr_BinaryOp_Coalesce(
|
|
|
|
left: Expr_Variable(
|
|
|
|
name: a
|
|
|
|
comments: array(
|
|
|
|
0: // null coalesce
|
|
|
|
)
|
|
|
|
)
|
|
|
|
right: Expr_Variable(
|
|
|
|
name: b
|
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // null coalesce
|
|
|
|
)
|
2015-03-12 22:45:38 +01:00
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
comments: array(
|
|
|
|
0: // null coalesce
|
|
|
|
)
|
2015-03-12 22:45:38 +01:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
5: Stmt_Expression(
|
|
|
|
expr: Expr_BinaryOp_Coalesce(
|
2015-03-12 22:45:38 +01:00
|
|
|
left: Expr_Variable(
|
2017-01-19 22:25:22 +01:00
|
|
|
name: a
|
2015-03-12 22:45:38 +01:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
right: Expr_BinaryOp_Coalesce(
|
|
|
|
left: Expr_Variable(
|
|
|
|
name: b
|
|
|
|
)
|
|
|
|
right: Expr_Variable(
|
|
|
|
name: c
|
|
|
|
)
|
2015-03-12 22:45:38 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
6: Stmt_Expression(
|
|
|
|
expr: Expr_Ternary(
|
|
|
|
cond: Expr_BinaryOp_Coalesce(
|
|
|
|
left: Expr_Variable(
|
|
|
|
name: a
|
|
|
|
)
|
|
|
|
right: Expr_Variable(
|
|
|
|
name: b
|
|
|
|
)
|
2015-03-12 22:45:38 +01:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
if: Expr_Variable(
|
|
|
|
name: c
|
|
|
|
)
|
|
|
|
else: Expr_Variable(
|
|
|
|
name: d
|
2015-03-12 22:45:38 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
7: Stmt_Expression(
|
|
|
|
expr: Expr_BinaryOp_Coalesce(
|
|
|
|
left: Expr_BinaryOp_BooleanAnd(
|
|
|
|
left: Expr_Variable(
|
|
|
|
name: a
|
|
|
|
)
|
|
|
|
right: Expr_Variable(
|
|
|
|
name: b
|
|
|
|
)
|
2015-03-12 22:45:38 +01:00
|
|
|
)
|
|
|
|
right: Expr_Variable(
|
2017-01-19 22:25:22 +01:00
|
|
|
name: c
|
2015-03-12 22:45:38 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2016-03-09 18:57:16 +01:00
|
|
|
)
|