1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-03 17:57:59 +01:00
PHP-Parser/test/code/parser/expr/ternaryAndCoalesce.test
Nikita Popov 01f4be6b4d Add support for null coalesce operator (??) [PHP 7]
Added as Expr\BinaryOp\Coalesce.
2015-03-12 22:45:56 +01:00

129 lines
2.4 KiB
Plaintext

Ternary operator
-----
<?php
// ternary
$a ? $b : $c;
$a ?: $c;
// precedence
$a ? $b : $c ? $d : $e;
$a ? $b : ($c ? $d : $e);
// null coalesce
$a ?? $b;
$a ?? $b ?? $c;
$a ?? $b ? $c : $d;
$a && $b ?? $c;
-----
array(
0: Expr_Ternary(
cond: Expr_Variable(
name: a
)
if: Expr_Variable(
name: b
)
else: Expr_Variable(
name: c
)
)
1: Expr_Ternary(
cond: Expr_Variable(
name: a
)
if: null
else: Expr_Variable(
name: c
)
)
2: Expr_Ternary(
cond: Expr_Ternary(
cond: Expr_Variable(
name: a
)
if: Expr_Variable(
name: b
)
else: Expr_Variable(
name: c
)
)
if: Expr_Variable(
name: d
)
else: Expr_Variable(
name: e
)
)
3: Expr_Ternary(
cond: Expr_Variable(
name: a
)
if: Expr_Variable(
name: b
)
else: Expr_Ternary(
cond: Expr_Variable(
name: c
)
if: Expr_Variable(
name: d
)
else: Expr_Variable(
name: e
)
)
)
4: Expr_BinaryOp_Coalesce(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
5: Expr_BinaryOp_Coalesce(
left: Expr_Variable(
name: a
)
right: Expr_BinaryOp_Coalesce(
left: Expr_Variable(
name: b
)
right: Expr_Variable(
name: c
)
)
)
6: Expr_Ternary(
cond: Expr_BinaryOp_Coalesce(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
if: Expr_Variable(
name: c
)
else: Expr_Variable(
name: d
)
)
7: Expr_BinaryOp_Coalesce(
left: Expr_BinaryOp_BooleanAnd(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
right: Expr_Variable(
name: c
)
)
)