First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,31 @@
Comments on blocks
-----
<?php
// foo
{
// bar
{
// baz
$a;
}
}
// empty
{}
-----
array(
0: Expr_Variable(
name: a
comments: array(
0: // foo
1: // bar
2: // baz
)
)
1: Stmt_Nop(
comments: array(
0: // empty
)
)
)

View file

@ -0,0 +1,100 @@
Comments
-----
<?php
/** doc 1 */
/* foobar 1 */
// foo 1
// bar 1
$var;
if ($cond) {
/** doc 2 */
/* foobar 2 */
// foo 2
// bar 2
}
/** doc 3 */
/* foobar 3 */
// foo 3
// bar 3
-----
array(
0: Expr_Variable(
name: var
comments: array(
0: /** doc 1 */
1: /* foobar 1 */
2: // foo 1
3: // bar 1
)
)
1: Stmt_If(
cond: Expr_Variable(
name: cond
)
stmts: array(
0: Stmt_Nop(
comments: array(
0: /** doc 2 */
1: /* foobar 2 */
2: // foo 2
3: // bar 2
)
)
)
elseifs: array(
)
else: null
)
2: Stmt_Nop(
comments: array(
0: /** doc 3 */
1: /* foobar 3 */
2: // foo 3
3: // bar 3
)
)
)
-----
<?php
/** doc */
/* foobar */
// foo
// bar
?>
-----
array(
0: Stmt_Nop(
comments: array(
0: /** doc */
1: /* foobar */
2: // foo
3: // bar
)
)
)
-----
<?php
// comment
if (42) {}
-----
array(
0: Stmt_If(
cond: Scalar_LNumber(
value: 42
)
stmts: array(
)
elseifs: array(
)
else: null
comments: array(
0: // comment
)
)
)

View file

@ -0,0 +1,32 @@
Error positions
-----
<?php foo
-----
Syntax error, unexpected EOF from 1:10 to 1:10
array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: foo
)
)
)
)
-----
<?php foo /* bar */
-----
Syntax error, unexpected EOF from 1:20 to 1:20
array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: foo
)
)
)
1: Stmt_Nop(
comments: array(
0: /* bar */
)
)
)

View file

@ -0,0 +1,124 @@
Lexer errors
-----
<?php
$a = 42;
/*
$b = 24;
-----
Unterminated comment from 4:1 to 5:9
array(
0: Expr_Assign(
var: Expr_Variable(
name: a
)
expr: Scalar_LNumber(
value: 42
)
)
1: Stmt_Nop(
comments: array(
0: /*
$b = 24;
)
)
)
-----
<?php
$a = 42;
@@{ "\1" }@@
$b = 24;
-----
Unexpected character "@@{ "\1" }@@" (ASCII 1) from 4:1 to 4:1
array(
0: Expr_Assign(
var: Expr_Variable(
name: a
)
expr: Scalar_LNumber(
value: 42
)
)
1: Expr_Assign(
var: Expr_Variable(
name: b
)
expr: Scalar_LNumber(
value: 24
)
)
)
-----
<?php
$a = 42;
@@{ "\0" }@@
$b = 24;
-----
Unexpected null byte from 4:1 to 4:1
array(
0: Expr_Assign(
var: Expr_Variable(
name: a
)
expr: Scalar_LNumber(
value: 42
)
)
1: Expr_Assign(
var: Expr_Variable(
name: b
)
expr: Scalar_LNumber(
value: 24
)
)
)
-----
<?php
$a = 1;
@@{ "\1" }@@
$b = 2;
@@{ "\2" }@@
$c = 3;
-----
Unexpected character "@@{ "\1" }@@" (ASCII 1) from 4:1 to 4:1
Unexpected character "@@{ "\2" }@@" (ASCII 2) from 6:1 to 6:1
array(
0: Expr_Assign(
var: Expr_Variable(
name: a
)
expr: Scalar_LNumber(
value: 1
)
)
1: Expr_Assign(
var: Expr_Variable(
name: b
)
expr: Scalar_LNumber(
value: 2
)
)
2: Expr_Assign(
var: Expr_Variable(
name: c
)
expr: Scalar_LNumber(
value: 3
)
)
)
-----
<?php
if ($b) {
$a = 1;
/* unterminated
}
-----
Unterminated comment from 5:5 to 6:2
Syntax error, unexpected EOF from 6:2 to 6:2

View file

@ -0,0 +1,866 @@
Error recovery
-----
<?php
foo()
bar()
baz()
-----
Syntax error, unexpected T_STRING from 4:1 to 4:3
Syntax error, unexpected T_STRING from 5:1 to 5:3
Syntax error, unexpected EOF from 5:6 to 5:6
array(
0: Expr_FuncCall(
name: Name(
parts: array(
0: foo
)
)
args: array(
)
)
1: Expr_FuncCall(
name: Name(
parts: array(
0: bar
)
)
args: array(
)
)
2: Expr_FuncCall(
name: Name(
parts: array(
0: baz
)
)
args: array(
)
)
)
-----
<?php
foo()
bar();
baz();
-----
Syntax error, unexpected T_STRING from 4:1 to 4:3
array(
0: Expr_FuncCall(
name: Name(
parts: array(
0: foo
)
)
args: array(
)
)
1: Expr_FuncCall(
name: Name(
parts: array(
0: bar
)
)
args: array(
)
)
2: Expr_FuncCall(
name: Name(
parts: array(
0: baz
)
)
args: array(
)
)
)
-----
<?php
foo();
bar()
baz();
-----
Syntax error, unexpected T_STRING from 5:1 to 5:3
array(
0: Expr_FuncCall(
name: Name(
parts: array(
0: foo
)
)
args: array(
)
)
1: Expr_FuncCall(
name: Name(
parts: array(
0: bar
)
)
args: array(
)
)
2: Expr_FuncCall(
name: Name(
parts: array(
0: baz
)
)
args: array(
)
)
)
-----
<?php
abc;
1 + ;
-----
Syntax error, unexpected ';' from 3:5 to 3:5
array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: abc
)
)
)
1: Scalar_LNumber(
value: 1
)
)
-----
<?php
function test() {
1 +
}
-----
Syntax error, unexpected '}' from 4:1 to 4:1
array(
0: Stmt_Function(
byRef: false
name: test
params: array(
)
returnType: null
stmts: array(
0: Scalar_LNumber(
value: 1
)
)
)
)
-----
<?php
$i = 0;
while
$j = 1;
$k = 2;
-----
Syntax error, unexpected T_VARIABLE, expecting '(' from 6:1 to 6:2
array(
0: Expr_Assign(
var: Expr_Variable(
name: i
)
expr: Scalar_LNumber(
value: 0
)
)
1: Expr_Assign(
var: Expr_Variable(
name: j
)
expr: Scalar_LNumber(
value: 1
)
)
2: Expr_Assign(
var: Expr_Variable(
name: k
)
expr: Scalar_LNumber(
value: 2
)
)
)
-----
<?php
$i = 0;
while () {
$j = 1;
}
$k = 2;
// The output here drops the loop - would require Error node to handle this
-----
Syntax error, unexpected ')' from 4:8 to 4:8
array(
0: Expr_Assign(
var: Expr_Variable(
name: i
)
expr: Scalar_LNumber(
value: 0
)
)
1: Expr_Assign(
var: Expr_Variable(
name: j
)
expr: Scalar_LNumber(
value: 1
)
)
2: Expr_Assign(
var: Expr_Variable(
name: k
)
expr: Scalar_LNumber(
value: 2
)
)
3: Stmt_Nop(
comments: array(
0: // The output here drops the loop - would require Error node to handle this
)
)
)
-----
<?php
// Can't recover this yet, as the '}' for the inner_statement_list
// is always required.
$i = 0;
while (true) {
$i = 1;
$i = 2;
-----
Syntax error, unexpected EOF from 8:12 to 8:12
-----
<?php
$foo->
;
-----
!!positions
Syntax error, unexpected ';', expecting T_STRING or T_VARIABLE or '{' or '$' from 3:1 to 3:1
array(
0: Expr_PropertyFetch[2:1 - 2:6](
var: Expr_Variable[2:1 - 2:4](
name: foo
)
name: Expr_Error[3:1 - 2:6](
)
)
)
-----
<?php
function foo() {
$bar->
}
-----
!!positions
Syntax error, unexpected '}', expecting T_STRING or T_VARIABLE or '{' or '$' from 4:1 to 4:1
array(
0: Stmt_Function[2:1 - 4:1](
byRef: false
name: foo
params: array(
)
returnType: null
stmts: array(
0: Expr_PropertyFetch[3:5 - 3:10](
var: Expr_Variable[3:5 - 3:8](
name: bar
)
name: Expr_Error[4:1 - 3:10](
)
)
)
)
)
-----
<?php
new T
-----
Syntax error, unexpected EOF from 2:6 to 2:6
array(
0: Expr_New(
class: Name(
parts: array(
0: T
)
)
args: array(
)
)
)
-----
<?php
new
-----
!!php7,positions
Syntax error, unexpected EOF from 2:4 to 2:4
array(
0: Expr_New[2:1 - 2:3](
class: Expr_Error[2:4 - 2:3](
)
args: array(
)
)
)
-----
<?php
$foo instanceof
-----
!!php7
Syntax error, unexpected EOF from 2:16 to 2:16
array(
0: Expr_Instanceof(
expr: Expr_Variable(
name: foo
)
class: Expr_Error(
)
)
)
-----
<?php
$
-----
!!php7
Syntax error, unexpected EOF, expecting T_VARIABLE or '{' or '$' from 2:2 to 2:2
array(
0: Expr_Variable(
name: Expr_Error(
)
)
)
-----
<?php
Foo::$
-----
!!php7
Syntax error, unexpected EOF, expecting T_VARIABLE or '{' or '$' from 2:7 to 2:7
array(
0: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: Foo
)
)
name: Expr_Error(
)
)
)
-----
<?php
Foo::
-----
!!php7
Syntax error, unexpected EOF from 2:6 to 2:6
array(
0: Expr_ClassConstFetch(
class: Name(
parts: array(
0: Foo
)
)
name: Expr_Error(
)
)
)
-----
<?php
namespace Foo
use A
use function a
use A\{B}
const A = 1
break
break 2
continue
continue 2
return
return 2
echo $a
unset($a)
throw $x
goto label
-----
!!php7
Syntax error, unexpected T_USE, expecting ';' or '{' from 3:1 to 3:3
Syntax error, unexpected T_USE, expecting ';' from 5:1 to 5:3
Syntax error, unexpected T_CONST, expecting ';' from 6:1 to 6:5
Syntax error, unexpected T_BREAK, expecting ';' from 7:1 to 7:5
Syntax error, unexpected T_THROW, expecting ';' from 15:1 to 15:5
array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: Foo
)
)
stmts: array(
0: Stmt_Use(
type: TYPE_NORMAL (1)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: A
)
)
alias: A
)
)
)
1: Stmt_Use(
type: TYPE_FUNCTION (2)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: a
)
)
alias: a
)
)
)
2: Stmt_GroupUse(
type: TYPE_UNKNOWN (0)
prefix: Name(
parts: array(
0: A
)
)
uses: array(
0: Stmt_UseUse(
type: TYPE_NORMAL (1)
name: Name(
parts: array(
0: B
)
)
alias: B
)
)
)
3: Stmt_Const(
consts: array(
0: Const(
name: A
value: Scalar_LNumber(
value: 1
)
)
)
)
4: Stmt_Break(
num: null
)
5: Stmt_Break(
num: Scalar_LNumber(
value: 2
)
)
6: Stmt_Continue(
num: null
)
7: Stmt_Continue(
num: Scalar_LNumber(
value: 2
)
)
8: Stmt_Return(
expr: null
)
9: Stmt_Return(
expr: Scalar_LNumber(
value: 2
)
)
10: Stmt_Echo(
exprs: array(
0: Expr_Variable(
name: a
)
)
)
11: Stmt_Unset(
vars: array(
0: Expr_Variable(
name: a
)
)
)
12: Stmt_Throw(
expr: Expr_Variable(
name: x
)
)
13: Stmt_Goto(
name: label
)
)
)
)
-----
<?php
use A\{B, };
use function A\{b, };
use A, ;
const A = 42, ;
class X implements Y, {
use A, ;
use A, {
A::b insteadof C, ;
}
const A = 42, ;
public $x, ;
}
interface I extends J, {}
unset($x, );
isset($x, );
declare(a=42, );
function foo($a, ) {}
foo($a, );
global $a, ;
static $a, ;
echo $a, ;
for ($a, ; $b, ; $c, );
function ($a, ) use ($b, ) {};
-----
!!php7
A trailing comma is not allowed here from 5:6 to 5:6
A trailing comma is not allowed here from 6:13 to 6:13
A trailing comma is not allowed here from 8:21 to 8:21
A trailing comma is not allowed here from 9:10 to 9:10
A trailing comma is not allowed here from 10:10 to 10:10
A trailing comma is not allowed here from 11:25 to 11:25
A trailing comma is not allowed here from 13:17 to 13:17
A trailing comma is not allowed here from 14:14 to 14:14
A trailing comma is not allowed here from 16:22 to 16:22
A trailing comma is not allowed here from 18:9 to 18:9
A trailing comma is not allowed here from 19:9 to 19:9
A trailing comma is not allowed here from 21:13 to 21:13
A trailing comma is not allowed here from 23:16 to 23:16
A trailing comma is not allowed here from 24:7 to 24:7
A trailing comma is not allowed here from 25:10 to 25:10
A trailing comma is not allowed here from 26:10 to 26:10
A trailing comma is not allowed here from 27:8 to 27:8
A trailing comma is not allowed here from 29:8 to 29:8
A trailing comma is not allowed here from 29:14 to 29:14
A trailing comma is not allowed here from 29:20 to 29:20
A trailing comma is not allowed here from 30:13 to 30:13
A trailing comma is not allowed here from 30:24 to 30:24
array(
0: Stmt_GroupUse(
type: TYPE_UNKNOWN (0)
prefix: Name(
parts: array(
0: A
)
)
uses: array(
0: Stmt_UseUse(
type: TYPE_NORMAL (1)
name: Name(
parts: array(
0: B
)
)
alias: B
)
)
)
1: Stmt_GroupUse(
type: TYPE_FUNCTION (2)
prefix: Name(
parts: array(
0: A
)
)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: b
)
)
alias: b
)
)
)
2: Stmt_Use(
type: TYPE_NORMAL (1)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: A
)
)
alias: A
)
)
)
3: Stmt_Const(
consts: array(
0: Const(
name: A
value: Scalar_LNumber(
value: 42
)
)
)
)
4: Stmt_Class(
flags: 0
name: X
extends: null
implements: array(
0: Name(
parts: array(
0: Y
)
)
)
stmts: array(
0: Stmt_TraitUse(
traits: array(
0: Name(
parts: array(
0: A
)
)
)
adaptations: array(
)
)
1: Stmt_TraitUse(
traits: array(
0: Name(
parts: array(
0: A
)
)
)
adaptations: array(
0: Stmt_TraitUseAdaptation_Precedence(
trait: Name(
parts: array(
0: A
)
)
method: b
insteadof: array(
0: Name(
parts: array(
0: C
)
)
)
)
)
)
2: Stmt_ClassConst(
flags: 0
consts: array(
0: Const(
name: A
value: Scalar_LNumber(
value: 42
)
)
)
)
3: Stmt_Property(
flags: MODIFIER_PUBLIC (1)
props: array(
0: Stmt_PropertyProperty(
name: x
default: null
)
)
)
)
)
5: Stmt_Interface(
name: I
extends: array(
0: Name(
parts: array(
0: J
)
)
)
stmts: array(
)
)
6: Stmt_Unset(
vars: array(
0: Expr_Variable(
name: x
)
)
)
7: Expr_Isset(
vars: array(
0: Expr_Variable(
name: x
)
)
)
8: Stmt_Declare(
declares: array(
0: Stmt_DeclareDeclare(
key: a
value: Scalar_LNumber(
value: 42
)
)
)
stmts: null
)
9: Stmt_Function(
byRef: false
name: foo
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
)
returnType: null
stmts: array(
)
)
10: Expr_FuncCall(
name: Name(
parts: array(
0: foo
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: a
)
byRef: false
unpack: false
)
)
)
11: Stmt_Global(
vars: array(
0: Expr_Variable(
name: a
)
)
)
12: Stmt_Static(
vars: array(
0: Stmt_StaticVar(
name: a
default: null
)
)
)
13: Stmt_Echo(
exprs: array(
0: Expr_Variable(
name: a
)
)
)
14: Stmt_For(
init: array(
0: Expr_Variable(
name: a
)
)
cond: array(
0: Expr_Variable(
name: b
)
)
loop: array(
0: Expr_Variable(
name: c
)
)
stmts: array(
)
)
15: Expr_Closure(
static: false
byRef: false
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
)
uses: array(
0: Expr_ClosureUse(
var: b
byRef: false
)
)
returnType: null
stmts: array(
)
)
)
-----
<?php
foo(Bar::);
-----
!!php7,positions
Syntax error, unexpected ')' from 3:10 to 3:10
array(
0: Expr_FuncCall[3:1 - 3:10](
name: Name[3:1 - 3:3](
parts: array(
0: foo
)
)
args: array(
0: Arg[3:5 - 3:9](
value: Expr_ClassConstFetch[3:5 - 3:9](
class: Name[3:5 - 3:7](
parts: array(
0: Bar
)
)
name: Expr_Error[3:10 - 3:9](
)
)
byRef: false
unpack: false
)
)
)
)

View file

@ -0,0 +1,142 @@
Array definitions
-----
<?php
array();
array('a');
array('a', );
array('a', 'b');
array('a', &$b, 'c' => 'd', 'e' => &$f);
// short array syntax
[];
[1, 2, 3];
['a' => 'b'];
-----
array(
0: Expr_Array(
items: array(
)
)
1: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_String(
value: a
)
byRef: false
)
)
)
2: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_String(
value: a
)
byRef: false
)
)
)
3: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_String(
value: a
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_String(
value: b
)
byRef: false
)
)
)
4: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_String(
value: a
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: b
)
byRef: true
)
2: Expr_ArrayItem(
key: Scalar_String(
value: c
)
value: Scalar_String(
value: d
)
byRef: false
)
3: Expr_ArrayItem(
key: Scalar_String(
value: e
)
value: Expr_Variable(
name: f
)
byRef: true
)
)
)
5: Expr_Array(
items: array(
)
comments: array(
0: // short array syntax
)
)
6: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 2
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 3
)
byRef: false
)
)
)
7: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Scalar_String(
value: b
)
byRef: false
)
)
)
)

View file

@ -0,0 +1,144 @@
Array destructuring
-----
<?php
[$a, $b] = [$c, $d];
[, $a, , , $b, ,] = $foo;
[, [[$a]], $b] = $bar;
['a' => $b, 'b' => $a] = $baz;
-----
!!php7
array(
0: Expr_Assign(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: a
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: b
)
byRef: false
)
)
)
expr: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: c
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: d
)
byRef: false
)
)
)
)
1: Expr_Assign(
var: Expr_Array(
items: array(
0: null
1: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: a
)
byRef: false
)
2: null
3: null
4: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: b
)
byRef: false
)
5: null
)
)
expr: Expr_Variable(
name: foo
)
)
2: Expr_Assign(
var: Expr_Array(
items: array(
0: null
1: Expr_ArrayItem(
key: null
value: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: a
)
byRef: false
)
)
)
byRef: false
)
)
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: b
)
byRef: false
)
)
)
expr: Expr_Variable(
name: bar
)
)
3: Expr_Assign(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Expr_Variable(
name: b
)
byRef: false
)
1: Expr_ArrayItem(
key: Scalar_String(
value: b
)
value: Expr_Variable(
name: a
)
byRef: false
)
)
)
expr: Expr_Variable(
name: baz
)
)
)

View file

@ -0,0 +1,301 @@
Assignments
-----
<?php
// simple assign
$a = $b;
// combined assign
$a &= $b;
$a |= $b;
$a ^= $b;
$a .= $b;
$a /= $b;
$a -= $b;
$a %= $b;
$a *= $b;
$a += $b;
$a <<= $b;
$a >>= $b;
$a **= $b;
// chained assign
$a = $b *= $c **= $d;
// by ref assign
$a =& $b;
// list() assign
list($a) = $b;
list($a, , $b) = $c;
list($a, list(, $c), $d) = $e;
// inc/dec
++$a;
$a++;
--$a;
$a--;
-----
array(
0: Expr_Assign(
var: Expr_Variable(
name: a
comments: array(
0: // simple assign
)
)
expr: Expr_Variable(
name: b
)
comments: array(
0: // simple assign
)
)
1: Expr_AssignOp_BitwiseAnd(
var: Expr_Variable(
name: a
comments: array(
0: // combined assign
)
)
expr: Expr_Variable(
name: b
)
comments: array(
0: // combined assign
)
)
2: Expr_AssignOp_BitwiseOr(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
3: Expr_AssignOp_BitwiseXor(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
4: Expr_AssignOp_Concat(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
5: Expr_AssignOp_Div(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
6: Expr_AssignOp_Minus(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
7: Expr_AssignOp_Mod(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
8: Expr_AssignOp_Mul(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
9: Expr_AssignOp_Plus(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
10: Expr_AssignOp_ShiftLeft(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
11: Expr_AssignOp_ShiftRight(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
12: Expr_AssignOp_Pow(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
13: Expr_Assign(
var: Expr_Variable(
name: a
comments: array(
0: // chained assign
)
)
expr: Expr_AssignOp_Mul(
var: Expr_Variable(
name: b
)
expr: Expr_AssignOp_Pow(
var: Expr_Variable(
name: c
)
expr: Expr_Variable(
name: d
)
)
)
comments: array(
0: // chained assign
)
)
14: Expr_AssignRef(
var: Expr_Variable(
name: a
comments: array(
0: // by ref assign
)
)
expr: Expr_Variable(
name: b
)
comments: array(
0: // by ref assign
)
)
15: Expr_Assign(
var: Expr_List(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: a
)
byRef: false
)
)
comments: array(
0: // list() assign
)
)
expr: Expr_Variable(
name: b
)
comments: array(
0: // list() assign
)
)
16: Expr_Assign(
var: Expr_List(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: a
)
byRef: false
)
1: null
2: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: b
)
byRef: false
)
)
)
expr: Expr_Variable(
name: c
)
)
17: Expr_Assign(
var: Expr_List(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: a
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Expr_List(
items: array(
0: null
1: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: c
)
byRef: false
)
)
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: d
)
byRef: false
)
)
)
expr: Expr_Variable(
name: e
)
)
18: Expr_PreInc(
var: Expr_Variable(
name: a
)
comments: array(
0: // inc/dec
)
)
19: Expr_PostInc(
var: Expr_Variable(
name: a
)
)
20: Expr_PreDec(
var: Expr_Variable(
name: a
)
)
21: Expr_PostDec(
var: Expr_Variable(
name: a
)
)
)

View file

@ -0,0 +1,39 @@
Assigning new by reference (PHP 5 only)
-----
<?php
$a =& new B;
-----
!!php5
array(
0: Expr_AssignRef(
var: Expr_Variable(
name: a
)
expr: Expr_New(
class: Name(
parts: array(
0: B
)
)
args: array(
)
)
)
)
-----
<?php
$a =& new B;
-----
!!php7
Syntax error, unexpected T_NEW from 2:7 to 2:9
array(
0: Expr_New(
class: Name(
parts: array(
0: B
)
)
args: array(
)
)
)

View file

@ -0,0 +1,72 @@
Casts
-----
<?php
(array) $a;
(bool) $a;
(boolean) $a;
(real) $a;
(double) $a;
(float) $a;
(int) $a;
(integer) $a;
(object) $a;
(string) $a;
(unset) $a;
-----
array(
0: Expr_Cast_Array(
expr: Expr_Variable(
name: a
)
)
1: Expr_Cast_Bool(
expr: Expr_Variable(
name: a
)
)
2: Expr_Cast_Bool(
expr: Expr_Variable(
name: a
)
)
3: Expr_Cast_Double(
expr: Expr_Variable(
name: a
)
)
4: Expr_Cast_Double(
expr: Expr_Variable(
name: a
)
)
5: Expr_Cast_Double(
expr: Expr_Variable(
name: a
)
)
6: Expr_Cast_Int(
expr: Expr_Variable(
name: a
)
)
7: Expr_Cast_Int(
expr: Expr_Variable(
name: a
)
)
8: Expr_Cast_Object(
expr: Expr_Variable(
name: a
)
)
9: Expr_Cast_String(
expr: Expr_Variable(
name: a
)
)
10: Expr_Cast_Unset(
expr: Expr_Variable(
name: a
)
)
)

View file

@ -0,0 +1,13 @@
Clone
-----
<?php
clone $a;
-----
array(
0: Expr_Clone(
expr: Expr_Variable(
name: a
)
)
)

View file

@ -0,0 +1,142 @@
Closures
-----
<?php
function($a) { $a; };
function($a) use($b) {};
function() use($a, &$b) {};
function &($a) {};
static function() {};
function($a) : array {};
function() use($a) : \Foo\Bar {};
-----
array(
0: Expr_Closure(
static: false
byRef: false
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
)
uses: array(
)
returnType: null
stmts: array(
0: Expr_Variable(
name: a
)
)
)
1: Expr_Closure(
static: false
byRef: false
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
)
uses: array(
0: Expr_ClosureUse(
var: b
byRef: false
)
)
returnType: null
stmts: array(
)
)
2: Expr_Closure(
static: false
byRef: false
params: array(
)
uses: array(
0: Expr_ClosureUse(
var: a
byRef: false
)
1: Expr_ClosureUse(
var: b
byRef: true
)
)
returnType: null
stmts: array(
)
)
3: Expr_Closure(
static: false
byRef: true
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
)
uses: array(
)
returnType: null
stmts: array(
)
)
4: Expr_Closure(
static: true
byRef: false
params: array(
)
uses: array(
)
returnType: null
stmts: array(
)
)
5: Expr_Closure(
static: false
byRef: false
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
)
uses: array(
)
returnType: array
stmts: array(
)
)
6: Expr_Closure(
static: false
byRef: false
params: array(
)
uses: array(
0: Expr_ClosureUse(
var: a
byRef: false
)
)
returnType: Name_FullyQualified(
parts: array(
0: Foo
1: Bar
)
)
stmts: array(
)
)
)

View file

@ -0,0 +1,107 @@
Comparison operators
-----
<?php
$a < $b;
$a <= $b;
$a > $b;
$a >= $b;
$a == $b;
$a === $b;
$a != $b;
$a !== $b;
$a <=> $b;
$a instanceof B;
$a instanceof $b;
-----
array(
0: Expr_BinaryOp_Smaller(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
1: Expr_BinaryOp_SmallerOrEqual(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
2: Expr_BinaryOp_Greater(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
3: Expr_BinaryOp_GreaterOrEqual(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
4: Expr_BinaryOp_Equal(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
5: Expr_BinaryOp_Identical(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
6: Expr_BinaryOp_NotEqual(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
7: Expr_BinaryOp_NotIdentical(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
8: Expr_BinaryOp_Spaceship(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
9: Expr_Instanceof(
expr: Expr_Variable(
name: a
)
class: Name(
parts: array(
0: B
)
)
)
10: Expr_Instanceof(
expr: Expr_Variable(
name: a
)
class: Expr_Variable(
name: b
)
)
)

View file

@ -0,0 +1,621 @@
Expressions in static scalar context
-----
<?php
const T_1 = 1 << 1;
const T_2 = 1 / 2;
const T_3 = 1.5 + 1.5;
const T_4 = "foo" . "bar";
const T_5 = (1.5 + 1.5) * 2;
const T_6 = "foo" . 2 . 3 . 4.0;
const T_7 = __LINE__;
const T_8 = <<<ENDOFSTRING
This is a test string
ENDOFSTRING;
const T_9 = ~-1;
const T_10 = (-1?:1) + (0?2:3);
const T_11 = 1 && 0;
const T_12 = 1 and 1;
const T_13 = 0 || 0;
const T_14 = 1 or 0;
const T_15 = 1 xor 1;
const T_16 = 1 xor 0;
const T_17 = 1 < 0;
const T_18 = 0 <= 0;
const T_19 = 1 > 0;
const T_20 = 1 >= 0;
const T_21 = 1 === 1;
const T_22 = 1 !== 1;
const T_23 = 0 != "0";
const T_24 = 1 == "1";
const T_25 = 1 + 2 * 3;
const T_26 = "1" + 2 + "3";
const T_27 = 2 ** 3;
const T_28 = [1, 2, 3][1];
const T_29 = 12 - 13;
const T_30 = 12 ^ 13;
const T_31 = 12 & 13;
const T_32 = 12 | 13;
const T_33 = 12 % 3;
const T_34 = 100 >> 4;
const T_35 = !false;
-----
array(
0: Stmt_Const(
consts: array(
0: Const(
name: T_1
value: Expr_BinaryOp_ShiftLeft(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 1
)
)
)
)
)
1: Stmt_Const(
consts: array(
0: Const(
name: T_2
value: Expr_BinaryOp_Div(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 2
)
)
)
)
)
2: Stmt_Const(
consts: array(
0: Const(
name: T_3
value: Expr_BinaryOp_Plus(
left: Scalar_DNumber(
value: 1.5
)
right: Scalar_DNumber(
value: 1.5
)
)
)
)
)
3: Stmt_Const(
consts: array(
0: Const(
name: T_4
value: Expr_BinaryOp_Concat(
left: Scalar_String(
value: foo
)
right: Scalar_String(
value: bar
)
)
)
)
)
4: Stmt_Const(
consts: array(
0: Const(
name: T_5
value: Expr_BinaryOp_Mul(
left: Expr_BinaryOp_Plus(
left: Scalar_DNumber(
value: 1.5
)
right: Scalar_DNumber(
value: 1.5
)
)
right: Scalar_LNumber(
value: 2
)
)
)
)
)
5: Stmt_Const(
consts: array(
0: Const(
name: T_6
value: Expr_BinaryOp_Concat(
left: Expr_BinaryOp_Concat(
left: Expr_BinaryOp_Concat(
left: Scalar_String(
value: foo
)
right: Scalar_LNumber(
value: 2
)
)
right: Scalar_LNumber(
value: 3
)
)
right: Scalar_DNumber(
value: 4
)
)
)
)
)
6: Stmt_Const(
consts: array(
0: Const(
name: T_7
value: Scalar_MagicConst_Line(
)
)
)
)
7: Stmt_Const(
consts: array(
0: Const(
name: T_8
value: Scalar_String(
value: This is a test string
)
)
)
)
8: Stmt_Const(
consts: array(
0: Const(
name: T_9
value: Expr_BitwiseNot(
expr: Expr_UnaryMinus(
expr: Scalar_LNumber(
value: 1
)
)
)
)
)
)
9: Stmt_Const(
consts: array(
0: Const(
name: T_10
value: Expr_BinaryOp_Plus(
left: Expr_Ternary(
cond: Expr_UnaryMinus(
expr: Scalar_LNumber(
value: 1
)
)
if: null
else: Scalar_LNumber(
value: 1
)
)
right: Expr_Ternary(
cond: Scalar_LNumber(
value: 0
)
if: Scalar_LNumber(
value: 2
)
else: Scalar_LNumber(
value: 3
)
)
)
)
)
)
10: Stmt_Const(
consts: array(
0: Const(
name: T_11
value: Expr_BinaryOp_BooleanAnd(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 0
)
)
)
)
)
11: Stmt_Const(
consts: array(
0: Const(
name: T_12
value: Expr_BinaryOp_LogicalAnd(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 1
)
)
)
)
)
12: Stmt_Const(
consts: array(
0: Const(
name: T_13
value: Expr_BinaryOp_BooleanOr(
left: Scalar_LNumber(
value: 0
)
right: Scalar_LNumber(
value: 0
)
)
)
)
)
13: Stmt_Const(
consts: array(
0: Const(
name: T_14
value: Expr_BinaryOp_LogicalOr(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 0
)
)
)
)
)
14: Stmt_Const(
consts: array(
0: Const(
name: T_15
value: Expr_BinaryOp_LogicalXor(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 1
)
)
)
)
)
15: Stmt_Const(
consts: array(
0: Const(
name: T_16
value: Expr_BinaryOp_LogicalXor(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 0
)
)
)
)
)
16: Stmt_Const(
consts: array(
0: Const(
name: T_17
value: Expr_BinaryOp_Smaller(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 0
)
)
)
)
)
17: Stmt_Const(
consts: array(
0: Const(
name: T_18
value: Expr_BinaryOp_SmallerOrEqual(
left: Scalar_LNumber(
value: 0
)
right: Scalar_LNumber(
value: 0
)
)
)
)
)
18: Stmt_Const(
consts: array(
0: Const(
name: T_19
value: Expr_BinaryOp_Greater(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 0
)
)
)
)
)
19: Stmt_Const(
consts: array(
0: Const(
name: T_20
value: Expr_BinaryOp_GreaterOrEqual(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 0
)
)
)
)
)
20: Stmt_Const(
consts: array(
0: Const(
name: T_21
value: Expr_BinaryOp_Identical(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 1
)
)
)
)
)
21: Stmt_Const(
consts: array(
0: Const(
name: T_22
value: Expr_BinaryOp_NotIdentical(
left: Scalar_LNumber(
value: 1
)
right: Scalar_LNumber(
value: 1
)
)
)
)
)
22: Stmt_Const(
consts: array(
0: Const(
name: T_23
value: Expr_BinaryOp_NotEqual(
left: Scalar_LNumber(
value: 0
)
right: Scalar_String(
value: 0
)
)
)
)
)
23: Stmt_Const(
consts: array(
0: Const(
name: T_24
value: Expr_BinaryOp_Equal(
left: Scalar_LNumber(
value: 1
)
right: Scalar_String(
value: 1
)
)
)
)
)
24: Stmt_Const(
consts: array(
0: Const(
name: T_25
value: Expr_BinaryOp_Plus(
left: Scalar_LNumber(
value: 1
)
right: Expr_BinaryOp_Mul(
left: Scalar_LNumber(
value: 2
)
right: Scalar_LNumber(
value: 3
)
)
)
)
)
)
25: Stmt_Const(
consts: array(
0: Const(
name: T_26
value: Expr_BinaryOp_Plus(
left: Expr_BinaryOp_Plus(
left: Scalar_String(
value: 1
)
right: Scalar_LNumber(
value: 2
)
)
right: Scalar_String(
value: 3
)
)
)
)
)
26: Stmt_Const(
consts: array(
0: Const(
name: T_27
value: Expr_BinaryOp_Pow(
left: Scalar_LNumber(
value: 2
)
right: Scalar_LNumber(
value: 3
)
)
)
)
)
27: Stmt_Const(
consts: array(
0: Const(
name: T_28
value: Expr_ArrayDimFetch(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 2
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 3
)
byRef: false
)
)
)
dim: Scalar_LNumber(
value: 1
)
)
)
)
)
28: Stmt_Const(
consts: array(
0: Const(
name: T_29
value: Expr_BinaryOp_Minus(
left: Scalar_LNumber(
value: 12
)
right: Scalar_LNumber(
value: 13
)
)
)
)
)
29: Stmt_Const(
consts: array(
0: Const(
name: T_30
value: Expr_BinaryOp_BitwiseXor(
left: Scalar_LNumber(
value: 12
)
right: Scalar_LNumber(
value: 13
)
)
)
)
)
30: Stmt_Const(
consts: array(
0: Const(
name: T_31
value: Expr_BinaryOp_BitwiseAnd(
left: Scalar_LNumber(
value: 12
)
right: Scalar_LNumber(
value: 13
)
)
)
)
)
31: Stmt_Const(
consts: array(
0: Const(
name: T_32
value: Expr_BinaryOp_BitwiseOr(
left: Scalar_LNumber(
value: 12
)
right: Scalar_LNumber(
value: 13
)
)
)
)
)
32: Stmt_Const(
consts: array(
0: Const(
name: T_33
value: Expr_BinaryOp_Mod(
left: Scalar_LNumber(
value: 12
)
right: Scalar_LNumber(
value: 3
)
)
)
)
)
33: Stmt_Const(
consts: array(
0: Const(
name: T_34
value: Expr_BinaryOp_ShiftRight(
left: Scalar_LNumber(
value: 100
)
right: Scalar_LNumber(
value: 4
)
)
)
)
)
34: Stmt_Const(
consts: array(
0: Const(
name: T_35
value: Expr_BooleanNot(
expr: Expr_ConstFetch(
name: Name(
parts: array(
0: false
)
)
)
)
)
)
)
)

View file

@ -0,0 +1,12 @@
Error suppression
-----
<?php
@$a;
-----
array(
0: Expr_ErrorSuppress(
expr: Expr_Variable(
name: a
)
)
)

View file

@ -0,0 +1,34 @@
Exit
-----
<?php
exit;
exit();
exit('Die!');
die;
die();
die('Exit!');
-----
array(
0: Expr_Exit(
expr: null
)
1: Expr_Exit(
expr: null
)
2: Expr_Exit(
expr: Scalar_String(
value: Die!
)
)
3: Expr_Exit(
expr: null
)
4: Expr_Exit(
expr: null
)
5: Expr_Exit(
expr: Scalar_String(
value: Exit!
)
)
)

View file

@ -0,0 +1,99 @@
Arguments
-----
<?php
f();
f($a);
f($a, $b);
f(&$a);
f($a, ...$b);
-----
array(
0: Expr_FuncCall(
name: Name(
parts: array(
0: f
)
)
args: array(
)
)
1: Expr_FuncCall(
name: Name(
parts: array(
0: f
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: a
)
byRef: false
unpack: false
)
)
)
2: Expr_FuncCall(
name: Name(
parts: array(
0: f
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: a
)
byRef: false
unpack: false
)
1: Arg(
value: Expr_Variable(
name: b
)
byRef: false
unpack: false
)
)
)
3: Expr_FuncCall(
name: Name(
parts: array(
0: f
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: a
)
byRef: true
unpack: false
)
)
)
4: Expr_FuncCall(
name: Name(
parts: array(
0: f
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: a
)
byRef: false
unpack: false
)
1: Arg(
value: Expr_Variable(
name: b
)
byRef: false
unpack: true
)
)
)
)

View file

@ -0,0 +1,33 @@
Constant fetches
-----
<?php
A;
A::B;
A::class;
-----
array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: A
)
)
)
1: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: B
)
2: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: class
)
)

View file

@ -0,0 +1,231 @@
Array/string dereferencing
-----
<?php
"abc"[2];
"abc"[2][0][0];
[1, 2, 3][2];
[1, 2, 3][2][0][0];
array(1, 2, 3)[2];
array(1, 2, 3)[2][0][0];
FOO[0];
Foo::BAR[1];
$foo::BAR[2][1][0];
-----
array(
0: Expr_ArrayDimFetch(
var: Scalar_String(
value: abc
)
dim: Scalar_LNumber(
value: 2
)
)
1: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Scalar_String(
value: abc
)
dim: Scalar_LNumber(
value: 2
)
)
dim: Scalar_LNumber(
value: 0
)
)
dim: Scalar_LNumber(
value: 0
)
)
2: Expr_ArrayDimFetch(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 2
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 3
)
byRef: false
)
)
)
dim: Scalar_LNumber(
value: 2
)
)
3: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 2
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 3
)
byRef: false
)
)
)
dim: Scalar_LNumber(
value: 2
)
)
dim: Scalar_LNumber(
value: 0
)
)
dim: Scalar_LNumber(
value: 0
)
)
4: Expr_ArrayDimFetch(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 2
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 3
)
byRef: false
)
)
)
dim: Scalar_LNumber(
value: 2
)
)
5: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 2
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 3
)
byRef: false
)
)
)
dim: Scalar_LNumber(
value: 2
)
)
dim: Scalar_LNumber(
value: 0
)
)
dim: Scalar_LNumber(
value: 0
)
)
6: Expr_ArrayDimFetch(
var: Expr_ConstFetch(
name: Name(
parts: array(
0: FOO
)
)
)
dim: Scalar_LNumber(
value: 0
)
)
7: Expr_ArrayDimFetch(
var: Expr_ClassConstFetch(
class: Name(
parts: array(
0: Foo
)
)
name: BAR
)
dim: Scalar_LNumber(
value: 1
)
)
8: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_ClassConstFetch(
class: Expr_Variable(
name: foo
)
name: BAR
)
dim: Scalar_LNumber(
value: 2
)
)
dim: Scalar_LNumber(
value: 1
)
)
dim: Scalar_LNumber(
value: 0
)
)
)

View file

@ -0,0 +1,132 @@
Function calls
-----
<?php
// function name variations
a();
$a();
${'a'}();
$$a();
$$$a();
$a['b']();
$a{'b'}();
$a->b['c']();
// array dereferencing
a()['b'];
-----
array(
0: Expr_FuncCall(
name: Name(
parts: array(
0: a
)
comments: array(
0: // function name variations
)
)
args: array(
)
comments: array(
0: // function name variations
)
)
1: Expr_FuncCall(
name: Expr_Variable(
name: a
)
args: array(
)
)
2: Expr_FuncCall(
name: Expr_Variable(
name: Scalar_String(
value: a
)
)
args: array(
)
)
3: Expr_FuncCall(
name: Expr_Variable(
name: Expr_Variable(
name: a
)
)
args: array(
)
)
4: Expr_FuncCall(
name: Expr_Variable(
name: Expr_Variable(
name: Expr_Variable(
name: a
)
)
)
args: array(
)
)
5: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
args: array(
)
)
6: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
args: array(
)
)
7: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
dim: Scalar_String(
value: c
)
)
args: array(
)
)
8: Expr_ArrayDimFetch(
var: Expr_FuncCall(
name: Name(
parts: array(
0: a
)
comments: array(
0: // array dereferencing
)
)
args: array(
)
comments: array(
0: // array dereferencing
)
)
dim: Scalar_String(
value: b
)
comments: array(
0: // array dereferencing
)
)
)

View file

@ -0,0 +1,70 @@
New expression dereferencing
-----
<?php
(new A)->b;
(new A)->b();
(new A)['b'];
(new A)['b']['c'];
-----
array(
0: Expr_PropertyFetch(
var: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
name: b
)
1: Expr_MethodCall(
var: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
name: b
args: array(
)
)
2: Expr_ArrayDimFetch(
var: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
dim: Scalar_String(
value: b
)
)
3: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
dim: Scalar_String(
value: b
)
)
dim: Scalar_String(
value: c
)
)
)

View file

@ -0,0 +1,145 @@
Object access
-----
<?php
// property fetch variations
$a->b;
$a->b['c'];
$a->b{'c'};
// method call variations
$a->b();
$a->{'b'}();
$a->$b();
$a->$b['c']();
// array dereferencing
$a->b()['c'];
$a->b(){'c'}; // invalid PHP: drop Support?
-----
!!php5
array(
0: Expr_PropertyFetch(
var: Expr_Variable(
name: a
comments: array(
0: // property fetch variations
)
)
name: b
comments: array(
0: // property fetch variations
)
)
1: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
dim: Scalar_String(
value: c
)
)
2: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
dim: Scalar_String(
value: c
)
)
3: Expr_MethodCall(
var: Expr_Variable(
name: a
comments: array(
0: // method call variations
)
)
name: b
args: array(
)
comments: array(
0: // method call variations
)
)
4: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: Scalar_String(
value: b
)
args: array(
)
)
5: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: Expr_Variable(
name: b
)
args: array(
)
)
6: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: Expr_ArrayDimFetch(
var: Expr_Variable(
name: b
)
dim: Scalar_String(
value: c
)
)
args: array(
)
)
7: Expr_ArrayDimFetch(
var: Expr_MethodCall(
var: Expr_Variable(
name: a
comments: array(
0: // array dereferencing
)
)
name: b
args: array(
)
comments: array(
0: // array dereferencing
)
)
dim: Scalar_String(
value: c
)
comments: array(
0: // array dereferencing
)
)
8: Expr_ArrayDimFetch(
var: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: b
args: array(
)
)
dim: Scalar_String(
value: c
)
)
9: Stmt_Nop(
comments: array(
0: // invalid PHP: drop Support?
)
)
)

View file

@ -0,0 +1,62 @@
Simple array access
-----
<?php
$a['b'];
$a['b']['c'];
$a[] = $b;
$a{'b'};
${$a}['b'];
-----
array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
1: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
dim: Scalar_String(
value: c
)
)
2: Expr_Assign(
var: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: null
)
expr: Expr_Variable(
name: b
)
)
3: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
4: Expr_ArrayDimFetch(
var: Expr_Variable(
name: Expr_Variable(
name: a
)
)
dim: Scalar_String(
value: b
)
)
)

View file

@ -0,0 +1,173 @@
Static calls
-----
<?php
// method name variations
A::b();
A::{'b'}();
A::$b();
A::$b['c']();
A::$b['c']['d']();
// array dereferencing
A::b()['c'];
// class name variations
static::b();
$a::b();
${'a'}::b();
$a['b']::c();
-----
!!php5
array(
0: Expr_StaticCall(
class: Name(
parts: array(
0: A
)
comments: array(
0: // method name variations
)
)
name: b
args: array(
)
comments: array(
0: // method name variations
)
)
1: Expr_StaticCall(
class: Name(
parts: array(
0: A
)
)
name: Scalar_String(
value: b
)
args: array(
)
)
2: Expr_StaticCall(
class: Name(
parts: array(
0: A
)
)
name: Expr_Variable(
name: b
)
args: array(
)
)
3: Expr_StaticCall(
class: Name(
parts: array(
0: A
)
)
name: Expr_ArrayDimFetch(
var: Expr_Variable(
name: b
)
dim: Scalar_String(
value: c
)
)
args: array(
)
)
4: Expr_StaticCall(
class: Name(
parts: array(
0: A
)
)
name: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_Variable(
name: b
)
dim: Scalar_String(
value: c
)
)
dim: Scalar_String(
value: d
)
)
args: array(
)
)
5: Expr_ArrayDimFetch(
var: Expr_StaticCall(
class: Name(
parts: array(
0: A
)
comments: array(
0: // array dereferencing
)
)
name: b
args: array(
)
comments: array(
0: // array dereferencing
)
)
dim: Scalar_String(
value: c
)
comments: array(
0: // array dereferencing
)
)
6: Expr_StaticCall(
class: Name(
parts: array(
0: static
)
comments: array(
0: // class name variations
)
)
name: b
args: array(
)
comments: array(
0: // class name variations
)
)
7: Expr_StaticCall(
class: Expr_Variable(
name: a
)
name: b
args: array(
)
)
8: Expr_StaticCall(
class: Expr_Variable(
name: Scalar_String(
value: a
)
)
name: b
args: array(
)
)
9: Expr_StaticCall(
class: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
name: c
args: array(
)
)
)

View file

@ -0,0 +1,91 @@
Static property fetches
-----
<?php
// property name variations
A::$b;
A::$$b;
A::${'b'};
// array access
A::$b['c'];
A::$b{'c'};
// class name variations can be found in staticCall.test
-----
array(
0: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
comments: array(
0: // property name variations
)
)
name: b
comments: array(
0: // property name variations
)
)
1: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: Expr_Variable(
name: b
)
)
2: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: Scalar_String(
value: b
)
)
3: Expr_ArrayDimFetch(
var: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
comments: array(
0: // array access
)
)
name: b
comments: array(
0: // array access
)
)
dim: Scalar_String(
value: c
)
comments: array(
0: // array access
)
)
4: Expr_ArrayDimFetch(
var: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: b
)
dim: Scalar_String(
value: c
)
)
5: Stmt_Nop(
comments: array(
0: // class name variations can be found in staticCall.test
)
)
)

View file

@ -0,0 +1,40 @@
Include and eval
-----
<?php
include 'A.php';
include_once 'A.php';
require 'A.php';
require_once 'A.php';
eval('A');
-----
array(
0: Expr_Include(
expr: Scalar_String(
value: A.php
)
type: TYPE_INCLUDE (1)
)
1: Expr_Include(
expr: Scalar_String(
value: A.php
)
type: TYPE_INCLUDE_ONCE (2)
)
2: Expr_Include(
expr: Scalar_String(
value: A.php
)
type: TYPE_REQUIRE (3)
)
3: Expr_Include(
expr: Scalar_String(
value: A.php
)
type: TYPE_REQURE_ONCE (4)
)
4: Expr_Eval(
expr: Scalar_String(
value: A
)
)
)

View file

@ -0,0 +1,75 @@
isset() and empty()
-----
<?php
isset($a);
isset($a, $b, $c);
empty($a);
empty(foo());
empty(array(1, 2, 3));
-----
array(
0: Expr_Isset(
vars: array(
0: Expr_Variable(
name: a
)
)
)
1: Expr_Isset(
vars: array(
0: Expr_Variable(
name: a
)
1: Expr_Variable(
name: b
)
2: Expr_Variable(
name: c
)
)
)
2: Expr_Empty(
expr: Expr_Variable(
name: a
)
)
3: Expr_Empty(
expr: Expr_FuncCall(
name: Name(
parts: array(
0: foo
)
)
args: array(
)
)
)
4: Expr_Empty(
expr: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 2
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 3
)
byRef: false
)
)
)
)
)

View file

@ -0,0 +1,75 @@
List destructing with keys
-----
<?php
list('a' => $b) = ['a' => 'b'];
list('a' => list($b => $c), 'd' => $e) = $x;
-----
!!php7
array(
0: Expr_Assign(
var: Expr_List(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Expr_Variable(
name: b
)
byRef: false
)
)
)
expr: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Scalar_String(
value: b
)
byRef: false
)
)
)
)
1: Expr_Assign(
var: Expr_List(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Expr_List(
items: array(
0: Expr_ArrayItem(
key: Expr_Variable(
name: b
)
value: Expr_Variable(
name: c
)
byRef: false
)
)
)
byRef: false
)
1: Expr_ArrayItem(
key: Scalar_String(
value: d
)
value: Expr_Variable(
name: e
)
byRef: false
)
)
)
expr: Expr_Variable(
name: x
)
)
)

View file

@ -0,0 +1,159 @@
Logical operators
-----
<?php
// boolean ops
$a && $b;
$a || $b;
!$a;
!!$a;
// logical ops
$a and $b;
$a or $b;
$a xor $b;
// precedence
$a && $b || $c && $d;
$a && ($b || $c) && $d;
$a = $b || $c;
$a = $b or $c;
-----
array(
0: Expr_BinaryOp_BooleanAnd(
left: Expr_Variable(
name: a
comments: array(
0: // boolean ops
)
)
right: Expr_Variable(
name: b
)
comments: array(
0: // boolean ops
)
)
1: Expr_BinaryOp_BooleanOr(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
2: Expr_BooleanNot(
expr: Expr_Variable(
name: a
)
)
3: Expr_BooleanNot(
expr: Expr_BooleanNot(
expr: Expr_Variable(
name: a
)
)
)
4: Expr_BinaryOp_LogicalAnd(
left: Expr_Variable(
name: a
comments: array(
0: // logical ops
)
)
right: Expr_Variable(
name: b
)
comments: array(
0: // logical ops
)
)
5: Expr_BinaryOp_LogicalOr(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
6: Expr_BinaryOp_LogicalXor(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
7: Expr_BinaryOp_BooleanOr(
left: Expr_BinaryOp_BooleanAnd(
left: Expr_Variable(
name: a
comments: array(
0: // precedence
)
)
right: Expr_Variable(
name: b
)
comments: array(
0: // precedence
)
)
right: Expr_BinaryOp_BooleanAnd(
left: Expr_Variable(
name: c
)
right: Expr_Variable(
name: d
)
)
comments: array(
0: // precedence
)
)
8: Expr_BinaryOp_BooleanAnd(
left: Expr_BinaryOp_BooleanAnd(
left: Expr_Variable(
name: a
)
right: Expr_BinaryOp_BooleanOr(
left: Expr_Variable(
name: b
)
right: Expr_Variable(
name: c
)
)
)
right: Expr_Variable(
name: d
)
)
9: Expr_Assign(
var: Expr_Variable(
name: a
)
expr: Expr_BinaryOp_BooleanOr(
left: Expr_Variable(
name: b
)
right: Expr_Variable(
name: c
)
)
)
10: Expr_BinaryOp_LogicalOr(
left: Expr_Assign(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
right: Expr_Variable(
name: c
)
)
)

View file

@ -0,0 +1,256 @@
Mathematical operators
-----
<?php
// unary ops
~$a;
+$a;
-$a;
// binary ops
$a & $b;
$a | $b;
$a ^ $b;
$a . $b;
$a / $b;
$a - $b;
$a % $b;
$a * $b;
$a + $b;
$a << $b;
$a >> $b;
$a ** $b;
// associativity
$a * $b * $c;
$a * ($b * $c);
// precedence
$a + $b * $c;
($a + $b) * $c;
// pow is special
$a ** $b ** $c;
($a ** $b) ** $c;
-----
array(
0: Expr_BitwiseNot(
expr: Expr_Variable(
name: a
)
comments: array(
0: // unary ops
)
)
1: Expr_UnaryPlus(
expr: Expr_Variable(
name: a
)
)
2: Expr_UnaryMinus(
expr: Expr_Variable(
name: a
)
)
3: Expr_BinaryOp_BitwiseAnd(
left: Expr_Variable(
name: a
comments: array(
0: // binary ops
)
)
right: Expr_Variable(
name: b
)
comments: array(
0: // binary ops
)
)
4: Expr_BinaryOp_BitwiseOr(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
5: Expr_BinaryOp_BitwiseXor(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
6: Expr_BinaryOp_Concat(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
7: Expr_BinaryOp_Div(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
8: Expr_BinaryOp_Minus(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
9: Expr_BinaryOp_Mod(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
10: Expr_BinaryOp_Mul(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
11: Expr_BinaryOp_Plus(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
12: Expr_BinaryOp_ShiftLeft(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
13: Expr_BinaryOp_ShiftRight(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
14: Expr_BinaryOp_Pow(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
15: Expr_BinaryOp_Mul(
left: Expr_BinaryOp_Mul(
left: Expr_Variable(
name: a
comments: array(
0: // associativity
)
)
right: Expr_Variable(
name: b
)
comments: array(
0: // associativity
)
)
right: Expr_Variable(
name: c
)
comments: array(
0: // associativity
)
)
16: Expr_BinaryOp_Mul(
left: Expr_Variable(
name: a
)
right: Expr_BinaryOp_Mul(
left: Expr_Variable(
name: b
)
right: Expr_Variable(
name: c
)
)
)
17: Expr_BinaryOp_Plus(
left: Expr_Variable(
name: a
comments: array(
0: // precedence
)
)
right: Expr_BinaryOp_Mul(
left: Expr_Variable(
name: b
)
right: Expr_Variable(
name: c
)
)
comments: array(
0: // precedence
)
)
18: Expr_BinaryOp_Mul(
left: Expr_BinaryOp_Plus(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
right: Expr_Variable(
name: c
)
)
19: Expr_BinaryOp_Pow(
left: Expr_Variable(
name: a
comments: array(
0: // pow is special
)
)
right: Expr_BinaryOp_Pow(
left: Expr_Variable(
name: b
)
right: Expr_Variable(
name: c
)
)
comments: array(
0: // pow is special
)
)
20: Expr_BinaryOp_Pow(
left: Expr_BinaryOp_Pow(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
right: Expr_Variable(
name: c
)
)
)

View file

@ -0,0 +1,146 @@
New
-----
<?php
new A;
new A($b);
// class name variations
new $a();
new $a['b']();
new A::$b();
// DNCR object access
new $a->b();
new $a->b->c();
new $a->b['c']();
new $a->b{'c'}();
// test regression introduces by new dereferencing syntax
(new A);
-----
array(
0: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
1: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: b
)
byRef: false
unpack: false
)
)
)
2: Expr_New(
class: Expr_Variable(
name: a
)
args: array(
)
comments: array(
0: // class name variations
)
)
3: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
args: array(
)
)
4: Expr_New(
class: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: b
)
args: array(
)
)
5: Expr_New(
class: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
args: array(
)
comments: array(
0: // DNCR object access
)
)
6: Expr_New(
class: Expr_PropertyFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
name: c
)
args: array(
)
)
7: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
dim: Scalar_String(
value: c
)
)
args: array(
)
)
8: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
dim: Scalar_String(
value: c
)
)
args: array(
)
)
9: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
)

View file

@ -0,0 +1,23 @@
New without a class
-----
<?php
new;
-----
!!php5
Syntax error, unexpected ';' from 2:4 to 2:4
array(
)
-----
<?php
new;
-----
!!php7
Syntax error, unexpected ';' from 2:4 to 2:4
array(
0: Expr_New(
class: Expr_Error(
)
args: array(
)
)
)

View file

@ -0,0 +1,12 @@
Print
-----
<?php
print $a;
-----
array(
0: Expr_Print(
expr: Expr_Variable(
name: a
)
)
)

View file

@ -0,0 +1,46 @@
Shell execution
-----
<?php
``;
`test`;
`test $A`;
`test \``;
`test \"`;
-----
array(
0: Expr_ShellExec(
parts: array(
)
)
1: Expr_ShellExec(
parts: array(
0: Scalar_EncapsedStringPart(
value: test
)
)
)
2: Expr_ShellExec(
parts: array(
0: Scalar_EncapsedStringPart(
value: test
)
1: Expr_Variable(
name: A
)
)
)
3: Expr_ShellExec(
parts: array(
0: Scalar_EncapsedStringPart(
value: test `
)
)
)
4: Expr_ShellExec(
parts: array(
0: Scalar_EncapsedStringPart(
value: test \"
)
)
)
)

View file

@ -0,0 +1,149 @@
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
comments: array(
0: // ternary
)
)
if: Expr_Variable(
name: b
)
else: Expr_Variable(
name: c
)
comments: array(
0: // ternary
)
)
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
comments: array(
0: // precedence
)
)
if: Expr_Variable(
name: b
)
else: Expr_Variable(
name: c
)
comments: array(
0: // precedence
)
)
if: Expr_Variable(
name: d
)
else: Expr_Variable(
name: e
)
comments: array(
0: // precedence
)
)
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
comments: array(
0: // null coalesce
)
)
right: Expr_Variable(
name: b
)
comments: array(
0: // null coalesce
)
)
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
)
)
)

View file

@ -0,0 +1,25 @@
Non-simple variables are forbidden in PHP 7
-----
<?php
global $$foo->bar;
-----
!!php7
Syntax error, unexpected T_OBJECT_OPERATOR, expecting ';' from 2:13 to 2:14
array(
0: Stmt_Global(
vars: array(
0: Expr_Variable(
name: Expr_Variable(
name: foo
)
)
)
)
1: Expr_ConstFetch(
name: Name(
parts: array(
0: bar
)
)
)
)

View file

@ -0,0 +1,481 @@
UVS indirect calls
-----
<?php
id('var_dump')(1);
id('id')('var_dump')(2);
id()()('var_dump')(4);
id(['udef', 'id'])[1]()('var_dump')(5);
(function($x) { return $x; })('id')('var_dump')(8);
($f = function($x = null) use (&$f) {
return $x ?: $f;
})()()()('var_dump')(9);
[$obj, 'id']()('id')($id)('var_dump')(10);
'id'()('id')('var_dump')(12);
('i' . 'd')()('var_dump')(13);
'\id'('var_dump')(14);
-----
!!php7
array(
0: Expr_FuncCall(
name: Expr_FuncCall(
name: Name(
parts: array(
0: id
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 1
)
byRef: false
unpack: false
)
)
)
1: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Name(
parts: array(
0: id
)
)
args: array(
0: Arg(
value: Scalar_String(
value: id
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 2
)
byRef: false
unpack: false
)
)
)
2: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Name(
parts: array(
0: id
)
)
args: array(
)
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 4
)
byRef: false
unpack: false
)
)
)
3: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_FuncCall(
name: Name(
parts: array(
0: id
)
)
args: array(
0: Arg(
value: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_String(
value: udef
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_String(
value: id
)
byRef: false
)
)
)
byRef: false
unpack: false
)
)
)
dim: Scalar_LNumber(
value: 1
)
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 5
)
byRef: false
unpack: false
)
)
)
4: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_Closure(
static: false
byRef: false
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: x
default: null
)
)
uses: array(
)
returnType: null
stmts: array(
0: Stmt_Return(
expr: Expr_Variable(
name: x
)
)
)
)
args: array(
0: Arg(
value: Scalar_String(
value: id
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 8
)
byRef: false
unpack: false
)
)
)
5: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_Assign(
var: Expr_Variable(
name: f
)
expr: Expr_Closure(
static: false
byRef: false
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: x
default: Expr_ConstFetch(
name: Name(
parts: array(
0: null
)
)
)
)
)
uses: array(
0: Expr_ClosureUse(
var: f
byRef: true
)
)
returnType: null
stmts: array(
0: Stmt_Return(
expr: Expr_Ternary(
cond: Expr_Variable(
name: x
)
if: null
else: Expr_Variable(
name: f
)
)
)
)
)
)
args: array(
)
)
args: array(
)
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 9
)
byRef: false
unpack: false
)
)
)
6: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: obj
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_String(
value: id
)
byRef: false
)
)
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: id
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: id
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 10
)
byRef: false
unpack: false
)
)
)
7: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Scalar_String(
value: id
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: id
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 12
)
byRef: false
unpack: false
)
)
)
8: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_FuncCall(
name: Expr_BinaryOp_Concat(
left: Scalar_String(
value: i
)
right: Scalar_String(
value: d
)
)
args: array(
)
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 13
)
byRef: false
unpack: false
)
)
)
9: Expr_FuncCall(
name: Expr_FuncCall(
name: Scalar_String(
value: \id
)
args: array(
0: Arg(
value: Scalar_String(
value: var_dump
)
byRef: false
unpack: false
)
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 14
)
byRef: false
unpack: false
)
)
)
)

View file

@ -0,0 +1,74 @@
UVS isset() on temporaries
-----
<?php
isset(([0, 1] + [])[0]);
isset(['a' => 'b']->a);
isset("str"->a);
-----
!!php7
array(
0: Expr_Isset(
vars: array(
0: Expr_ArrayDimFetch(
var: Expr_BinaryOp_Plus(
left: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 0
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
)
)
right: Expr_Array(
items: array(
)
)
)
dim: Scalar_LNumber(
value: 0
)
)
)
)
1: Expr_Isset(
vars: array(
0: Expr_PropertyFetch(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Scalar_String(
value: b
)
byRef: false
)
)
)
name: a
)
)
)
2: Expr_Isset(
vars: array(
0: Expr_PropertyFetch(
var: Scalar_String(
value: str
)
name: a
)
)
)
)

View file

@ -0,0 +1,109 @@
Uniform variable syntax in PHP 7 (misc)
-----
<?php
A::A[0];
A::A[0][1][2];
"string"->length();
(clone $obj)->b[0](1);
[0, 1][0] = 1;
-----
!!php7
array(
0: Expr_ArrayDimFetch(
var: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: A
)
dim: Scalar_LNumber(
value: 0
)
)
1: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: A
)
dim: Scalar_LNumber(
value: 0
)
)
dim: Scalar_LNumber(
value: 1
)
)
dim: Scalar_LNumber(
value: 2
)
)
2: Expr_MethodCall(
var: Scalar_String(
value: string
)
name: length
args: array(
)
)
3: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Clone(
expr: Expr_Variable(
name: obj
)
)
name: b
)
dim: Scalar_LNumber(
value: 0
)
)
args: array(
0: Arg(
value: Scalar_LNumber(
value: 1
)
byRef: false
unpack: false
)
)
)
4: Expr_Assign(
var: Expr_ArrayDimFetch(
var: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 0
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
)
)
dim: Scalar_LNumber(
value: 0
)
)
expr: Scalar_LNumber(
value: 1
)
)
)

View file

@ -0,0 +1,95 @@
UVS new expressions
-----
<?php
new $className;
new $array['className'];
new $array{'className'};
new $obj->className;
new Test::$className;
new $test::$className;
new $weird[0]->foo::$className;
-----
!!php7
array(
0: Expr_New(
class: Expr_Variable(
name: className
)
args: array(
)
)
1: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_Variable(
name: array
)
dim: Scalar_String(
value: className
)
)
args: array(
)
)
2: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_Variable(
name: array
)
dim: Scalar_String(
value: className
)
)
args: array(
)
)
3: Expr_New(
class: Expr_PropertyFetch(
var: Expr_Variable(
name: obj
)
name: className
)
args: array(
)
)
4: Expr_New(
class: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: Test
)
)
name: className
)
args: array(
)
)
5: Expr_New(
class: Expr_StaticPropertyFetch(
class: Expr_Variable(
name: test
)
name: className
)
args: array(
)
)
6: Expr_New(
class: Expr_StaticPropertyFetch(
class: Expr_PropertyFetch(
var: Expr_ArrayDimFetch(
var: Expr_Variable(
name: weird
)
dim: Scalar_LNumber(
value: 0
)
)
name: foo
)
name: className
)
args: array(
)
)
)

View file

@ -0,0 +1,93 @@
UVS static access
-----
<?php
A::$b;
$A::$b;
'A'::$b;
('A' . '')::$b;
'A'[0]::$b;
A::$$b;
A::$$c[1];
A::$A::$b;
-----
!!php7
array(
0: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: b
)
1: Expr_StaticPropertyFetch(
class: Expr_Variable(
name: A
)
name: b
)
2: Expr_StaticPropertyFetch(
class: Scalar_String(
value: A
)
name: b
)
3: Expr_StaticPropertyFetch(
class: Expr_BinaryOp_Concat(
left: Scalar_String(
value: A
)
right: Scalar_String(
value:
)
)
name: b
)
4: Expr_StaticPropertyFetch(
class: Expr_ArrayDimFetch(
var: Scalar_String(
value: A
)
dim: Scalar_LNumber(
value: 0
)
)
name: b
)
5: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: Expr_Variable(
name: b
)
)
6: Expr_ArrayDimFetch(
var: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: Expr_Variable(
name: c
)
)
dim: Scalar_LNumber(
value: 1
)
)
7: Expr_StaticPropertyFetch(
class: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: A
)
name: b
)
)

View file

@ -0,0 +1,55 @@
Variable syntaxes
-----
<?php
$a;
${'a'};
${foo()};
$$a;
$$$a;
$$a['b'];
-----
!!php5
array(
0: Expr_Variable(
name: a
)
1: Expr_Variable(
name: Scalar_String(
value: a
)
)
2: Expr_Variable(
name: Expr_FuncCall(
name: Name(
parts: array(
0: foo
)
)
args: array(
)
)
)
3: Expr_Variable(
name: Expr_Variable(
name: a
)
)
4: Expr_Variable(
name: Expr_Variable(
name: Expr_Variable(
name: a
)
)
)
5: Expr_Variable(
name: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
)
)

View file

@ -0,0 +1,60 @@
Constant string syntaxes
-----
<?php
'';
"";
b'';
b"";
'Hi';
b'Hi';
B'Hi';
"Hi";
b"Hi";
B"Hi";
'!\'!\\!\a!';
"!\"!\\!\$!\n!\r!\t!\f!\v!\e!\a";
"!\xFF!\377!\400!\0!";
-----
array(
0: Scalar_String(
value:
)
1: Scalar_String(
value:
)
2: Scalar_String(
value:
)
3: Scalar_String(
value:
)
4: Scalar_String(
value: Hi
)
5: Scalar_String(
value: Hi
)
6: Scalar_String(
value: Hi
)
7: Scalar_String(
value: Hi
)
8: Scalar_String(
value: Hi
)
9: Scalar_String(
value: Hi
)
10: Scalar_String(
value: !'!\!\a!
)
11: Scalar_String(
value: !"!\!$!
!@@{ "\r" }@@!@@{ "\t" }@@!@@{ "\f" }@@!@@{ "\v" }@@!@@{ chr(27) /* "\e" */ }@@!\a
)
12: Scalar_String(
value: !@@{ chr(255) }@@!@@{ chr(255) }@@!@@{ chr(0) }@@!@@{ chr(0) }@@!
)
)

View file

@ -0,0 +1,90 @@
Nowdoc and heredoc strings
-----
<?php
// empty strings
<<<'EOS'
EOS;
<<<EOS
EOS;
// constant encapsed strings
<<<'EOS'
Test '" $a \n
EOS;
<<<EOS
Test '" \$a \n
EOS;
// encapsed strings
<<<EOS
Test $a
EOS;
<<<EOS
Test $a and $b->c test
EOS;
b<<<EOS
Binary
EOS;
-----
array(
0: Scalar_String(
value:
comments: array(
0: // empty strings
)
)
1: Scalar_String(
value:
)
2: Scalar_String(
value: Test '" $a \n
comments: array(
0: // constant encapsed strings
)
)
3: Scalar_String(
value: Test '" $a
)
4: Scalar_Encapsed(
parts: array(
0: Scalar_EncapsedStringPart(
value: Test
)
1: Expr_Variable(
name: a
)
)
comments: array(
0: // encapsed strings
)
)
5: Scalar_Encapsed(
parts: array(
0: Scalar_EncapsedStringPart(
value: Test
)
1: Expr_Variable(
name: a
)
2: Scalar_EncapsedStringPart(
value: and
)
3: Expr_PropertyFetch(
var: Expr_Variable(
name: b
)
name: c
)
4: Scalar_EncapsedStringPart(
value: test
)
)
)
6: Scalar_String(
value: Binary
)
)

View file

@ -0,0 +1,61 @@
Trailing newlines in doc strings
-----
<?php
<<<'EOF'@@{ "\n\n" }@@EOF;
<<<'EOF'@@{ "\n\n\n" }@@EOF;
<<<'EOF'@@{ "\nFoo\n\n" }@@EOF;
<<<EOF@@{ "\n\$var\n\n" }@@EOF;
<<<'EOF'@@{ "\r\n\r\n" }@@EOF;
<<<'EOF'@@{ "\r\n\r\n\r\n" }@@EOF;
<<<'EOF'@@{ "\r\nFoo\r\n\r\n" }@@EOF;
<<<EOF@@{ "\r\n\$var\r\n\r\n" }@@EOF;
-----
array(
0: Scalar_String(
value:
)
1: Scalar_String(
value:
)
2: Scalar_String(
value: Foo
)
3: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: var
)
1: Scalar_EncapsedStringPart(
value:
)
)
)
4: Scalar_String(
value:
)
5: Scalar_String(
value:
)
6: Scalar_String(
value: Foo
)
7: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: var
)
1: Scalar_EncapsedStringPart(
value:
)
)
)
)

View file

@ -0,0 +1,72 @@
Encapsed string negative var offsets
-----
<?php
"$a[-0]";
"$a[-1]";
"$a[-0x0]";
"$a[-00]";
"$a[@@{ -PHP_INT_MAX - 1 }@@]";
-----
!!php7
array(
0: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: -0
)
)
)
)
1: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_LNumber(
value: -1
)
)
)
)
2: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: -0x0
)
)
)
)
3: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: -00
)
)
)
)
4: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_LNumber(
value: @@{ -PHP_INT_MAX - 1 }@@
)
)
)
)
)

View file

@ -0,0 +1,294 @@
Encapsed strings
-----
<?php
"$A";
"$A->B";
"$A[B]";
"$A[0]";
"$A[1234]";
"$A[9223372036854775808]";
"$A[000]";
"$A[0x0]";
"$A[0b0]";
"$A[$B]";
"{$A}";
"{$A['B']}";
"${A}";
"${A['B']}";
"${$A}";
"\{$A}";
"\{ $A }";
"\\{$A}";
"\\{ $A }";
"{$$A}[B]";
"$$A[B]";
"A $B C";
b"$A";
B"$A";
-----
array(
0: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: A
)
)
)
1: Scalar_Encapsed(
parts: array(
0: Expr_PropertyFetch(
var: Expr_Variable(
name: A
)
name: B
)
)
)
2: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Scalar_String(
value: B
)
)
)
)
3: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Scalar_LNumber(
value: 0
)
)
)
)
4: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Scalar_LNumber(
value: 1234
)
)
)
)
5: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Scalar_String(
value: 9223372036854775808
)
)
)
)
6: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Scalar_String(
value: 000
)
)
)
)
7: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Scalar_String(
value: 0x0
)
)
)
)
8: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Scalar_String(
value: 0b0
)
)
)
)
9: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Expr_Variable(
name: B
)
)
)
)
10: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: A
)
)
)
11: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Scalar_String(
value: B
)
)
)
)
12: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: A
)
)
)
13: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Scalar_String(
value: B
)
)
)
)
14: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: Expr_Variable(
name: A
)
)
)
)
15: Scalar_Encapsed(
parts: array(
0: Scalar_EncapsedStringPart(
value: \{
)
1: Expr_Variable(
name: A
)
2: Scalar_EncapsedStringPart(
value: }
)
)
)
16: Scalar_Encapsed(
parts: array(
0: Scalar_EncapsedStringPart(
value: \{
)
1: Expr_Variable(
name: A
)
2: Scalar_EncapsedStringPart(
value: }
)
)
)
17: Scalar_Encapsed(
parts: array(
0: Scalar_EncapsedStringPart(
value: \
)
1: Expr_Variable(
name: A
)
)
)
18: Scalar_Encapsed(
parts: array(
0: Scalar_EncapsedStringPart(
value: \{
)
1: Expr_Variable(
name: A
)
2: Scalar_EncapsedStringPart(
value: }
)
)
)
19: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: Expr_Variable(
name: A
)
)
1: Scalar_EncapsedStringPart(
value: [B]
)
)
)
20: Scalar_Encapsed(
parts: array(
0: Scalar_EncapsedStringPart(
value: $
)
1: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Scalar_String(
value: B
)
)
)
)
21: Scalar_Encapsed(
parts: array(
0: Scalar_EncapsedStringPart(
value: A
)
1: Expr_Variable(
name: B
)
2: Scalar_EncapsedStringPart(
value: C
)
)
)
22: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: A
)
)
)
23: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: A
)
)
)
)

View file

@ -0,0 +1,74 @@
Different float syntaxes
-----
<?php
0.0;
0.;
.0;
0e0;
0E0;
0e+0;
0e-0;
30.20e10;
300.200e100;
1e10000;
// various integer -> float overflows
// (all are actually the same number, just in different representations)
18446744073709551615;
0xFFFFFFFFFFFFFFFF;
01777777777777777777777;
0177777777777777777777787;
0b1111111111111111111111111111111111111111111111111111111111111111;
-----
array(
0: Scalar_DNumber(
value: 0
)
1: Scalar_DNumber(
value: 0
)
2: Scalar_DNumber(
value: 0
)
3: Scalar_DNumber(
value: 0
)
4: Scalar_DNumber(
value: 0
)
5: Scalar_DNumber(
value: 0
)
6: Scalar_DNumber(
value: 0
)
7: Scalar_DNumber(
value: 302000000000
)
8: Scalar_DNumber(
value: 3.002E+102
)
9: Scalar_DNumber(
value: INF
)
10: Scalar_DNumber(
value: 1.844674407371E+19
comments: array(
0: // various integer -> float overflows
1: // (all are actually the same number, just in different representations)
)
)
11: Scalar_DNumber(
value: 1.844674407371E+19
)
12: Scalar_DNumber(
value: 1.844674407371E+19
)
13: Scalar_DNumber(
value: 1.844674407371E+19
)
14: Scalar_DNumber(
value: 1.844674407371E+19
)
)

View file

@ -0,0 +1,43 @@
Different integer syntaxes
-----
<?php
0;
1;
@@{ PHP_INT_MAX }@@;
@@{ PHP_INT_MAX + 1 }@@;
0xFFF;
0xfff;
0XfFf;
0777;
0b111000111000;
-----
array(
0: Scalar_LNumber(
value: 0
)
1: Scalar_LNumber(
value: 1
)
2: Scalar_LNumber(
value: @@{ PHP_INT_MAX }@@
)
3: Scalar_DNumber(
value: @@{ PHP_INT_MAX + 1 }@@
)
4: Scalar_LNumber(
value: 4095
)
5: Scalar_LNumber(
value: 4095
)
6: Scalar_LNumber(
value: 4095
)
7: Scalar_LNumber(
value: 511
)
8: Scalar_LNumber(
value: 3640
)
)

View file

@ -0,0 +1,22 @@
Invalid octal literals
-----
<?php
0787;
-----
!!php7
Invalid numeric literal from 2:1 to 2:4
array(
0: Scalar_LNumber(
value: 0
)
)
-----
<?php
0787;
-----
!!php5
array(
0: Scalar_LNumber(
value: 7
)
)

View file

@ -0,0 +1,31 @@
Magic constants
-----
<?php
__CLASS__;
__DIR__;
__FILE__;
__FUNCTION__;
__LINE__;
__METHOD__;
__NAMESPACE__;
__TRAIT__;
-----
array(
0: Scalar_MagicConst_Class(
)
1: Scalar_MagicConst_Dir(
)
2: Scalar_MagicConst_File(
)
3: Scalar_MagicConst_Function(
)
4: Scalar_MagicConst_Line(
)
5: Scalar_MagicConst_Method(
)
6: Scalar_MagicConst_Namespace(
)
7: Scalar_MagicConst_Trait(
)
)

View file

@ -0,0 +1,20 @@
Unicode escape sequence
-----
<?php
"\u{0}";
"\u{114}";
"\u{1F602}";
-----
!!php7
array(
0: Scalar_String(
value: @@{"\0"}@@
)
1: Scalar_String(
value: Ĕ
)
2: Scalar_String(
value: @@{"\xF0\x9F\x98\x82"}@@
)
)

View file

@ -0,0 +1,382 @@
Valid usages of reserved keywords as identifiers
-----
<?php
class Test {
function array() {}
function public() {}
static function list() {}
static function protected() {}
public $class;
public $private;
const TRAIT = 3, FINAL = 4;
const __CLASS__ = 1, __TRAIT__ = 2, __FUNCTION__ = 3, __METHOD__ = 4, __LINE__ = 5,
__FILE__ = 6, __DIR__ = 7, __NAMESPACE__ = 8;
// __halt_compiler does not work
}
$t = new Test;
$t->array();
$t->public();
Test::list();
Test::protected();
$t->class;
$t->private;
Test::TRAIT;
Test::FINAL;
class Foo {
use TraitA, TraitB {
TraitA::catch insteadof namespace\TraitB;
TraitA::list as foreach;
TraitB::throw as protected public;
TraitB::self as protected;
exit as die;
\TraitC::exit as bye;
namespace\TraitC::exit as byebye;
TraitA::
//
/** doc comment */
#
catch /* comment */
// comment
# comment
insteadof TraitB;
}
}
-----
array(
0: Stmt_Class(
flags: 0
name: Test
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: 0
byRef: false
name: array
params: array(
)
returnType: null
stmts: array(
)
)
1: Stmt_ClassMethod(
flags: 0
byRef: false
name: public
params: array(
)
returnType: null
stmts: array(
)
)
2: Stmt_ClassMethod(
flags: MODIFIER_STATIC (8)
byRef: false
name: list
params: array(
)
returnType: null
stmts: array(
)
)
3: Stmt_ClassMethod(
flags: MODIFIER_STATIC (8)
byRef: false
name: protected
params: array(
)
returnType: null
stmts: array(
)
)
4: Stmt_Property(
flags: MODIFIER_PUBLIC (1)
props: array(
0: Stmt_PropertyProperty(
name: class
default: null
)
)
)
5: Stmt_Property(
flags: MODIFIER_PUBLIC (1)
props: array(
0: Stmt_PropertyProperty(
name: private
default: null
)
)
)
6: Stmt_ClassConst(
flags: 0
consts: array(
0: Const(
name: TRAIT
value: Scalar_LNumber(
value: 3
)
)
1: Const(
name: FINAL
value: Scalar_LNumber(
value: 4
)
)
)
)
7: Stmt_ClassConst(
flags: 0
consts: array(
0: Const(
name: __CLASS__
value: Scalar_LNumber(
value: 1
)
)
1: Const(
name: __TRAIT__
value: Scalar_LNumber(
value: 2
)
)
2: Const(
name: __FUNCTION__
value: Scalar_LNumber(
value: 3
)
)
3: Const(
name: __METHOD__
value: Scalar_LNumber(
value: 4
)
)
4: Const(
name: __LINE__
value: Scalar_LNumber(
value: 5
)
)
5: Const(
name: __FILE__
value: Scalar_LNumber(
value: 6
)
)
6: Const(
name: __DIR__
value: Scalar_LNumber(
value: 7
)
)
7: Const(
name: __NAMESPACE__
value: Scalar_LNumber(
value: 8
)
)
)
)
)
)
1: Expr_Assign(
var: Expr_Variable(
name: t
)
expr: Expr_New(
class: Name(
parts: array(
0: Test
)
)
args: array(
)
)
)
2: Expr_MethodCall(
var: Expr_Variable(
name: t
)
name: array
args: array(
)
)
3: Expr_MethodCall(
var: Expr_Variable(
name: t
)
name: public
args: array(
)
)
4: Expr_StaticCall(
class: Name(
parts: array(
0: Test
)
)
name: list
args: array(
)
)
5: Expr_StaticCall(
class: Name(
parts: array(
0: Test
)
)
name: protected
args: array(
)
)
6: Expr_PropertyFetch(
var: Expr_Variable(
name: t
)
name: class
)
7: Expr_PropertyFetch(
var: Expr_Variable(
name: t
)
name: private
)
8: Expr_ClassConstFetch(
class: Name(
parts: array(
0: Test
)
)
name: TRAIT
)
9: Expr_ClassConstFetch(
class: Name(
parts: array(
0: Test
)
)
name: FINAL
)
10: Stmt_Class(
flags: 0
name: Foo
extends: null
implements: array(
)
stmts: array(
0: Stmt_TraitUse(
traits: array(
0: Name(
parts: array(
0: TraitA
)
)
1: Name(
parts: array(
0: TraitB
)
)
)
adaptations: array(
0: Stmt_TraitUseAdaptation_Precedence(
trait: Name(
parts: array(
0: TraitA
)
)
method: catch
insteadof: array(
0: Name_Relative(
parts: array(
0: TraitB
)
)
)
)
1: Stmt_TraitUseAdaptation_Alias(
trait: Name(
parts: array(
0: TraitA
)
)
method: list
newModifier: null
newName: foreach
)
2: Stmt_TraitUseAdaptation_Alias(
trait: Name(
parts: array(
0: TraitB
)
)
method: throw
newModifier: MODIFIER_PROTECTED (2)
newName: public
)
3: Stmt_TraitUseAdaptation_Alias(
trait: Name(
parts: array(
0: TraitB
)
)
method: self
newModifier: MODIFIER_PROTECTED (2)
newName: null
)
4: Stmt_TraitUseAdaptation_Alias(
trait: null
method: exit
newModifier: null
newName: die
)
5: Stmt_TraitUseAdaptation_Alias(
trait: Name_FullyQualified(
parts: array(
0: TraitC
)
)
method: exit
newModifier: null
newName: bye
)
6: Stmt_TraitUseAdaptation_Alias(
trait: Name_Relative(
parts: array(
0: TraitC
)
)
method: exit
newModifier: null
newName: byebye
)
7: Stmt_TraitUseAdaptation_Precedence(
trait: Name(
parts: array(
0: TraitA
)
)
method: catch
insteadof: array(
0: Name(
parts: array(
0: TraitB
)
)
)
)
)
)
)
)
)

View file

@ -0,0 +1,112 @@
Blockless statements for if/for/etc
-----
<?php
if ($a) $A;
elseif ($b) $B;
else $C;
for (;;) $foo;
foreach ($a as $b) $AB;
while ($a) $A;
do $A; while ($a);
declare (a='b') $C;
-----
array(
0: Stmt_If(
cond: Expr_Variable(
name: a
)
stmts: array(
0: Expr_Variable(
name: A
)
)
elseifs: array(
0: Stmt_ElseIf(
cond: Expr_Variable(
name: b
)
stmts: array(
0: Expr_Variable(
name: B
)
)
)
)
else: Stmt_Else(
stmts: array(
0: Expr_Variable(
name: C
)
)
)
)
1: Stmt_For(
init: array(
)
cond: array(
)
loop: array(
)
stmts: array(
0: Expr_Variable(
name: foo
)
)
)
2: Stmt_Foreach(
expr: Expr_Variable(
name: a
)
keyVar: null
byRef: false
valueVar: Expr_Variable(
name: b
)
stmts: array(
0: Expr_Variable(
name: AB
)
)
)
3: Stmt_While(
cond: Expr_Variable(
name: a
)
stmts: array(
0: Expr_Variable(
name: A
)
)
)
4: Stmt_Do(
cond: Expr_Variable(
name: a
)
stmts: array(
0: Expr_Variable(
name: A
)
)
)
5: Stmt_Declare(
declares: array(
0: Stmt_DeclareDeclare(
key: a
value: Scalar_String(
value: b
)
)
)
stmts: array(
0: Expr_Variable(
name: C
)
)
)
)

View file

@ -0,0 +1,39 @@
Abstract class
-----
<?php
abstract class A {
public function a() {}
abstract public function b();
}
-----
array(
0: Stmt_Class(
flags: MODIFIER_ABSTRACT (16)
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_PUBLIC (1)
byRef: false
name: a
params: array(
)
returnType: null
stmts: array(
)
)
1: Stmt_ClassMethod(
flags: MODIFIER_PUBLIC | MODIFIER_ABSTRACT (17)
byRef: false
name: b
params: array(
)
returnType: null
stmts: null
)
)
)
)

View file

@ -0,0 +1,195 @@
Anonymous classes
-----
<?php
new class {
public function test() {}
};
new class extends A implements B, C {};
new class() {
public $foo;
};
new class($a, $b) extends A {
use T;
};
class A {
public function test() {
return new class($this) extends A {
const A = 'B';
};
}
}
-----
array(
0: Expr_New(
class: Stmt_Class(
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_PUBLIC (1)
byRef: false
name: test
params: array(
)
returnType: null
stmts: array(
)
)
)
)
args: array(
)
)
1: Expr_New(
class: Stmt_Class(
flags: 0
name: null
extends: Name(
parts: array(
0: A
)
)
implements: array(
0: Name(
parts: array(
0: B
)
)
1: Name(
parts: array(
0: C
)
)
)
stmts: array(
)
)
args: array(
)
)
2: Expr_New(
class: Stmt_Class(
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
0: Stmt_Property(
flags: MODIFIER_PUBLIC (1)
props: array(
0: Stmt_PropertyProperty(
name: foo
default: null
)
)
)
)
)
args: array(
)
)
3: Expr_New(
class: Stmt_Class(
flags: 0
name: null
extends: Name(
parts: array(
0: A
)
)
implements: array(
)
stmts: array(
0: Stmt_TraitUse(
traits: array(
0: Name(
parts: array(
0: T
)
)
)
adaptations: array(
)
)
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: a
)
byRef: false
unpack: false
)
1: Arg(
value: Expr_Variable(
name: b
)
byRef: false
unpack: false
)
)
)
4: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_PUBLIC (1)
byRef: false
name: test
params: array(
)
returnType: null
stmts: array(
0: Stmt_Return(
expr: Expr_New(
class: Stmt_Class(
flags: 0
name: null
extends: Name(
parts: array(
0: A
)
)
implements: array(
)
stmts: array(
0: Stmt_ClassConst(
flags: 0
consts: array(
0: Const(
name: A
value: Scalar_String(
value: B
)
)
)
)
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: this
)
byRef: false
unpack: false
)
)
)
)
)
)
)
)
)

View file

@ -0,0 +1,33 @@
Conditional class definition
-----
<?php
if (true) {
class A {}
}
-----
array(
0: Stmt_If(
cond: Expr_ConstFetch(
name: Name(
parts: array(
0: true
)
)
)
stmts: array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
)
)
)
elseifs: array(
)
else: null
)
)

View file

@ -0,0 +1,121 @@
Invalid class constant modifiers
-----
<?php
class A {
static const X = 1;
}
-----
!!php7
Cannot use 'static' as constant modifier from 3:5 to 3:10
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassConst(
flags: MODIFIER_STATIC (8)
consts: array(
0: Const(
name: X
value: Scalar_LNumber(
value: 1
)
)
)
)
)
)
)
-----
<?php
class A {
abstract const X = 1;
}
-----
!!php7
Cannot use 'abstract' as constant modifier from 3:5 to 3:12
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassConst(
flags: MODIFIER_ABSTRACT (16)
consts: array(
0: Const(
name: X
value: Scalar_LNumber(
value: 1
)
)
)
)
)
)
)
-----
<?php
class A {
final const X = 1;
}
-----
!!php7
Cannot use 'final' as constant modifier from 3:5 to 3:9
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassConst(
flags: MODIFIER_FINAL (32)
consts: array(
0: Const(
name: X
value: Scalar_LNumber(
value: 1
)
)
)
)
)
)
)
-----
<?php
class A {
public public const X = 1;
}
-----
!!php7
Multiple access type modifiers are not allowed from 3:12 to 3:17
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassConst(
flags: MODIFIER_PUBLIC (1)
consts: array(
0: Const(
name: X
value: Scalar_LNumber(
value: 1
)
)
)
)
)
)
)

View file

@ -0,0 +1,67 @@
Class constant modifiers
-----
<?php
class Foo {
const A = 1;
public const B = 2;
protected const C = 3;
private const D = 4;
}
-----
!!php7
array(
0: Stmt_Class(
flags: 0
name: Foo
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassConst(
flags: 0
consts: array(
0: Const(
name: A
value: Scalar_LNumber(
value: 1
)
)
)
)
1: Stmt_ClassConst(
flags: MODIFIER_PUBLIC (1)
consts: array(
0: Const(
name: B
value: Scalar_LNumber(
value: 2
)
)
)
)
2: Stmt_ClassConst(
flags: MODIFIER_PROTECTED (2)
consts: array(
0: Const(
name: C
value: Scalar_LNumber(
value: 3
)
)
)
)
3: Stmt_ClassConst(
flags: MODIFIER_PRIVATE (4)
consts: array(
0: Const(
name: D
value: Scalar_LNumber(
value: 4
)
)
)
)
)
)
)

View file

@ -0,0 +1,17 @@
Final class
-----
<?php
final class A {}
-----
array(
0: Stmt_Class(
flags: MODIFIER_FINAL (32)
name: A
extends: null
implements: array(
)
stmts: array(
)
)
)

View file

@ -0,0 +1,92 @@
Implicitly public properties and methods
-----
<?php
abstract class A {
var $a;
static $b;
abstract function c();
final function d() {}
static function e() {}
final static function f() {}
function g() {}
}
-----
array(
0: Stmt_Class(
flags: MODIFIER_ABSTRACT (16)
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_Property(
flags: 0
props: array(
0: Stmt_PropertyProperty(
name: a
default: null
)
)
)
1: Stmt_Property(
flags: MODIFIER_STATIC (8)
props: array(
0: Stmt_PropertyProperty(
name: b
default: null
)
)
)
2: Stmt_ClassMethod(
flags: MODIFIER_ABSTRACT (16)
byRef: false
name: c
params: array(
)
returnType: null
stmts: null
)
3: Stmt_ClassMethod(
flags: MODIFIER_FINAL (32)
byRef: false
name: d
params: array(
)
returnType: null
stmts: array(
)
)
4: Stmt_ClassMethod(
flags: MODIFIER_STATIC (8)
byRef: false
name: e
params: array(
)
returnType: null
stmts: array(
)
)
5: Stmt_ClassMethod(
flags: MODIFIER_STATIC | MODIFIER_FINAL (40)
byRef: false
name: f
params: array(
)
returnType: null
stmts: array(
)
)
6: Stmt_ClassMethod(
flags: 0
byRef: false
name: g
params: array(
)
returnType: null
stmts: array(
)
)
)
)
)

View file

@ -0,0 +1,36 @@
Interface
-----
<?php
interface A extends C, D {
public function a();
}
-----
array(
0: Stmt_Interface(
name: A
extends: array(
0: Name(
parts: array(
0: C
)
)
1: Name(
parts: array(
0: D
)
)
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_PUBLIC (1)
byRef: false
name: a
params: array(
)
returnType: null
stmts: null
)
)
)
)

View file

@ -0,0 +1,215 @@
Invalid modifier combination
-----
<?php class A { public public $a; }
-----
Multiple access type modifiers are not allowed from 1:24 to 1:29
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_Property(
flags: MODIFIER_PUBLIC (1)
props: array(
0: Stmt_PropertyProperty(
name: a
default: null
)
)
)
)
)
)
-----
<?php class A { public protected $a; }
-----
Multiple access type modifiers are not allowed from 1:24 to 1:32
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_Property(
flags: MODIFIER_PUBLIC | MODIFIER_PROTECTED (3)
props: array(
0: Stmt_PropertyProperty(
name: a
default: null
)
)
)
)
)
)
-----
<?php class A { abstract abstract function a(); }
-----
Multiple abstract modifiers are not allowed from 1:26 to 1:33
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_ABSTRACT (16)
byRef: false
name: a
params: array(
)
returnType: null
stmts: null
)
)
)
)
-----
<?php class A { static static $a; }
-----
Multiple static modifiers are not allowed from 1:24 to 1:29
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_Property(
flags: MODIFIER_STATIC (8)
props: array(
0: Stmt_PropertyProperty(
name: a
default: null
)
)
)
)
)
)
-----
<?php class A { final final function a() {} }
-----
Multiple final modifiers are not allowed from 1:23 to 1:27
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_FINAL (32)
byRef: false
name: a
params: array(
)
returnType: null
stmts: array(
)
)
)
)
)
-----
<?php class A { abstract final function a(); }
-----
Cannot use the final modifier on an abstract class member from 1:26 to 1:30
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_ABSTRACT | MODIFIER_FINAL (48)
byRef: false
name: a
params: array(
)
returnType: null
stmts: null
)
)
)
)
-----
<?php abstract final class A { }
// Type in the partial parse could conceivably be any of 0, 16 or 32
-----
Syntax error, unexpected T_FINAL, expecting T_CLASS from 1:16 to 1:20
array(
0: Stmt_Class(
flags: MODIFIER_FINAL (32)
name: A
extends: null
implements: array(
)
stmts: array(
)
)
1: Stmt_Nop(
comments: array(
0: // Type in the partial parse could conceivably be any of 0, 16 or 32
)
)
)
-----
<?php class A { abstract $a; }
-----
Properties cannot be declared abstract from 1:17 to 1:24
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_Property(
flags: MODIFIER_ABSTRACT (16)
props: array(
0: Stmt_PropertyProperty(
name: a
default: null
)
)
)
)
)
)
-----
<?php class A { final $a; }
-----
Properties cannot be declared final from 1:17 to 1:21
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_Property(
flags: MODIFIER_FINAL (32)
props: array(
0: Stmt_PropertyProperty(
name: a
default: null
)
)
)
)
)
)

View file

@ -0,0 +1,240 @@
Invalid class name
-----
<?php class self {}
-----
Cannot use 'self' as class name as it is reserved from 1:13 to 1:16
array(
0: Stmt_Class(
flags: 0
name: self
extends: null
implements: array(
)
stmts: array(
)
)
)
-----
<?php class PARENT {}
-----
Cannot use 'PARENT' as class name as it is reserved from 1:13 to 1:18
array(
0: Stmt_Class(
flags: 0
name: PARENT
extends: null
implements: array(
)
stmts: array(
)
)
)
-----
<?php class static {}
-----
Syntax error, unexpected T_STATIC, expecting T_STRING from 1:13 to 1:18
array(
)
-----
<?php class A extends self {}
-----
Cannot use 'self' as class name as it is reserved from 1:23 to 1:26
array(
0: Stmt_Class(
flags: 0
name: A
extends: Name(
parts: array(
0: self
)
)
implements: array(
)
stmts: array(
)
)
)
-----
<?php class A extends PARENT {}
-----
Cannot use 'PARENT' as class name as it is reserved from 1:23 to 1:28
array(
0: Stmt_Class(
flags: 0
name: A
extends: Name(
parts: array(
0: PARENT
)
)
implements: array(
)
stmts: array(
)
)
)
-----
<?php class A extends static {}
-----
Cannot use 'static' as class name as it is reserved from 1:23 to 1:28
array(
0: Stmt_Class(
flags: 0
name: A
extends: Name(
parts: array(
0: static
)
)
implements: array(
)
stmts: array(
)
)
)
-----
<?php class A implements self {}
-----
Cannot use 'self' as interface name as it is reserved from 1:26 to 1:29
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
0: Name(
parts: array(
0: self
)
)
)
stmts: array(
)
)
)
-----
<?php class A implements PARENT {}
-----
Cannot use 'PARENT' as interface name as it is reserved from 1:26 to 1:31
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
0: Name(
parts: array(
0: PARENT
)
)
)
stmts: array(
)
)
)
-----
<?php class A implements static {}
-----
Cannot use 'static' as interface name as it is reserved from 1:26 to 1:31
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
0: Name(
parts: array(
0: static
)
)
)
stmts: array(
)
)
)
-----
<?php interface self {}
-----
Cannot use 'self' as class name as it is reserved from 1:17 to 1:20
array(
0: Stmt_Interface(
name: self
extends: array(
)
stmts: array(
)
)
)
-----
<?php interface PARENT {}
-----
Cannot use 'PARENT' as class name as it is reserved from 1:17 to 1:22
array(
0: Stmt_Interface(
name: PARENT
extends: array(
)
stmts: array(
)
)
)
-----
<?php interface static {}
-----
Syntax error, unexpected T_STATIC, expecting T_STRING from 1:17 to 1:22
array(
)
-----
<?php interface A extends self {}
-----
Cannot use 'self' as interface name as it is reserved from 1:27 to 1:30
array(
0: Stmt_Interface(
name: A
extends: array(
0: Name(
parts: array(
0: self
)
)
)
stmts: array(
)
)
)
-----
<?php interface A extends PARENT {}
-----
Cannot use 'PARENT' as interface name as it is reserved from 1:27 to 1:32
array(
0: Stmt_Interface(
name: A
extends: array(
0: Name(
parts: array(
0: PARENT
)
)
)
stmts: array(
)
)
)
-----
<?php interface A extends static {}
-----
Cannot use 'static' as interface name as it is reserved from 1:27 to 1:32
array(
0: Stmt_Interface(
name: A
extends: array(
0: Name(
parts: array(
0: static
)
)
)
stmts: array(
)
)
)

View file

@ -0,0 +1,50 @@
PHP 4 style declarations
-----
<?php
class A {
var $foo;
function bar() {}
static abstract function baz() {}
}
-----
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_Property(
flags: 0
props: array(
0: Stmt_PropertyProperty(
name: foo
default: null
)
)
)
1: Stmt_ClassMethod(
flags: 0
byRef: false
name: bar
params: array(
)
returnType: null
stmts: array(
)
)
2: Stmt_ClassMethod(
flags: MODIFIER_ABSTRACT | MODIFIER_STATIC (24)
byRef: false
name: baz
params: array(
)
returnType: null
stmts: array(
)
)
)
)
)

View file

@ -0,0 +1,156 @@
Class declaration
-----
<?php
class A extends B implements C, D {
const A = 'B', C = 'D';
public $a = 'b', $c = 'd';
protected $e;
private $f;
public function a() {}
public static function b($a) {}
public final function c() : B {}
protected function d() {}
private function e() {}
}
-----
array(
0: Stmt_Class(
flags: 0
name: A
extends: Name(
parts: array(
0: B
)
)
implements: array(
0: Name(
parts: array(
0: C
)
)
1: Name(
parts: array(
0: D
)
)
)
stmts: array(
0: Stmt_ClassConst(
flags: 0
consts: array(
0: Const(
name: A
value: Scalar_String(
value: B
)
)
1: Const(
name: C
value: Scalar_String(
value: D
)
)
)
)
1: Stmt_Property(
flags: MODIFIER_PUBLIC (1)
props: array(
0: Stmt_PropertyProperty(
name: a
default: Scalar_String(
value: b
)
)
1: Stmt_PropertyProperty(
name: c
default: Scalar_String(
value: d
)
)
)
)
2: Stmt_Property(
flags: MODIFIER_PROTECTED (2)
props: array(
0: Stmt_PropertyProperty(
name: e
default: null
)
)
)
3: Stmt_Property(
flags: MODIFIER_PRIVATE (4)
props: array(
0: Stmt_PropertyProperty(
name: f
default: null
)
)
)
4: Stmt_ClassMethod(
flags: MODIFIER_PUBLIC (1)
byRef: false
name: a
params: array(
)
returnType: null
stmts: array(
)
)
5: Stmt_ClassMethod(
flags: MODIFIER_PUBLIC | MODIFIER_STATIC (9)
byRef: false
name: b
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
)
returnType: null
stmts: array(
)
)
6: Stmt_ClassMethod(
flags: MODIFIER_PUBLIC | MODIFIER_FINAL (33)
byRef: false
name: c
params: array(
)
returnType: Name(
parts: array(
0: B
)
)
stmts: array(
)
)
7: Stmt_ClassMethod(
flags: MODIFIER_PROTECTED (2)
byRef: false
name: d
params: array(
)
returnType: null
stmts: array(
)
)
8: Stmt_ClassMethod(
flags: MODIFIER_PRIVATE (4)
byRef: false
name: e
params: array(
)
returnType: null
stmts: array(
)
)
)
)
)

View file

@ -0,0 +1,151 @@
Some special methods cannot be static
-----
<?php class A { static function __construct() {} }
-----
Constructor __construct() cannot be static from 1:17 to 1:22
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_STATIC (8)
byRef: false
name: __construct
params: array(
)
returnType: null
stmts: array(
)
)
)
)
)
-----
<?php class A { static function __destruct() {} }
-----
Destructor __destruct() cannot be static from 1:17 to 1:22
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_STATIC (8)
byRef: false
name: __destruct
params: array(
)
returnType: null
stmts: array(
)
)
)
)
)
-----
<?php class A { static function __clone() {} }
-----
Clone method __clone() cannot be static from 1:17 to 1:22
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_STATIC (8)
byRef: false
name: __clone
params: array(
)
returnType: null
stmts: array(
)
)
)
)
)
-----
<?php class A { static function __CONSTRUCT() {} }
-----
Constructor __CONSTRUCT() cannot be static from 1:17 to 1:22
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_STATIC (8)
byRef: false
name: __CONSTRUCT
params: array(
)
returnType: null
stmts: array(
)
)
)
)
)
-----
<?php class A { static function __Destruct() {} }
-----
Destructor __Destruct() cannot be static from 1:17 to 1:22
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_STATIC (8)
byRef: false
name: __Destruct
params: array(
)
returnType: null
stmts: array(
)
)
)
)
)
-----
<?php class A { static function __cLoNe() {} }
-----
Clone method __cLoNe() cannot be static from 1:17 to 1:22
array(
0: Stmt_Class(
flags: 0
name: A
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_STATIC (8)
byRef: false
name: __cLoNe
params: array(
)
returnType: null
stmts: array(
)
)
)
)
)

View file

@ -0,0 +1,160 @@
Traits
-----
<?php
trait A {
public function a() {}
}
class B {
use C;
use D {
a as protected b;
c as d;
e as private;
}
use E, F, G {
E::a insteadof F, G;
E::b as protected c;
E::d as e;
E::f as private;
}
}
-----
array(
0: Stmt_Trait(
name: A
stmts: array(
0: Stmt_ClassMethod(
flags: MODIFIER_PUBLIC (1)
byRef: false
name: a
params: array(
)
returnType: null
stmts: array(
)
)
)
)
1: Stmt_Class(
flags: 0
name: B
extends: null
implements: array(
)
stmts: array(
0: Stmt_TraitUse(
traits: array(
0: Name(
parts: array(
0: C
)
)
)
adaptations: array(
)
)
1: Stmt_TraitUse(
traits: array(
0: Name(
parts: array(
0: D
)
)
)
adaptations: array(
0: Stmt_TraitUseAdaptation_Alias(
trait: null
method: a
newModifier: MODIFIER_PROTECTED (2)
newName: b
)
1: Stmt_TraitUseAdaptation_Alias(
trait: null
method: c
newModifier: null
newName: d
)
2: Stmt_TraitUseAdaptation_Alias(
trait: null
method: e
newModifier: MODIFIER_PRIVATE (4)
newName: null
)
)
)
2: Stmt_TraitUse(
traits: array(
0: Name(
parts: array(
0: E
)
)
1: Name(
parts: array(
0: F
)
)
2: Name(
parts: array(
0: G
)
)
)
adaptations: array(
0: Stmt_TraitUseAdaptation_Precedence(
trait: Name(
parts: array(
0: E
)
)
method: a
insteadof: array(
0: Name(
parts: array(
0: F
)
)
1: Name(
parts: array(
0: G
)
)
)
)
1: Stmt_TraitUseAdaptation_Alias(
trait: Name(
parts: array(
0: E
)
)
method: b
newModifier: MODIFIER_PROTECTED (2)
newName: c
)
2: Stmt_TraitUseAdaptation_Alias(
trait: Name(
parts: array(
0: E
)
)
method: d
newModifier: null
newName: e
)
3: Stmt_TraitUseAdaptation_Alias(
trait: Name(
parts: array(
0: E
)
)
method: f
newModifier: MODIFIER_PRIVATE (4)
newName: null
)
)
)
)
)
)

View file

@ -0,0 +1,40 @@
Global constants
-----
<?php
const A = 0, B = 1.0, C = 'A', D = E;
-----
array(
0: Stmt_Const(
consts: array(
0: Const(
name: A
value: Scalar_LNumber(
value: 0
)
)
1: Const(
name: B
value: Scalar_DNumber(
value: 1
)
)
2: Const(
name: C
value: Scalar_String(
value: A
)
)
3: Const(
name: D
value: Expr_ConstFetch(
name: Name(
parts: array(
0: E
)
)
)
)
)
)
)

View file

@ -0,0 +1,55 @@
Control flow statements
-----
<?php
break;
break 2;
continue;
continue 2;
return;
return $a;
throw $e;
label:
goto label;
-----
array(
0: Stmt_Break(
num: null
)
1: Stmt_Break(
num: Scalar_LNumber(
value: 2
)
)
2: Stmt_Continue(
num: null
)
3: Stmt_Continue(
num: Scalar_LNumber(
value: 2
)
)
4: Stmt_Return(
expr: null
)
5: Stmt_Return(
expr: Expr_Variable(
name: a
)
)
6: Stmt_Throw(
expr: Expr_Variable(
name: e
)
)
7: Stmt_Label(
name: label
)
8: Stmt_Goto(
name: label
)
)

View file

@ -0,0 +1,60 @@
Declare
-----
<?php
declare (X='Y');
declare (A='B', C='D') {}
declare (A='B', C='D'):
enddeclare;
-----
array(
0: Stmt_Declare(
declares: array(
0: Stmt_DeclareDeclare(
key: X
value: Scalar_String(
value: Y
)
)
)
stmts: null
)
1: Stmt_Declare(
declares: array(
0: Stmt_DeclareDeclare(
key: A
value: Scalar_String(
value: B
)
)
1: Stmt_DeclareDeclare(
key: C
value: Scalar_String(
value: D
)
)
)
stmts: array(
)
)
2: Stmt_Declare(
declares: array(
0: Stmt_DeclareDeclare(
key: A
value: Scalar_String(
value: B
)
)
1: Stmt_DeclareDeclare(
key: C
value: Scalar_String(
value: D
)
)
)
stmts: array(
)
)
)

View file

@ -0,0 +1,32 @@
Echo
-----
<?php
echo 'Hallo World!';
echo 'Hallo', ' ', 'World', '!';
-----
array(
0: Stmt_Echo(
exprs: array(
0: Scalar_String(
value: Hallo World!
)
)
)
1: Stmt_Echo(
exprs: array(
0: Scalar_String(
value: Hallo
)
1: Scalar_String(
value:
)
2: Scalar_String(
value: World
)
3: Scalar_String(
value: !
)
)
)
)

View file

@ -0,0 +1,59 @@
Scalar type declarations
-----
<?php
function test(bool $a, Int $b, FLOAT $c, StRiNg $d, iterable $e, object $f) : void {}
-----
!!php7
array(
0: Stmt_Function(
byRef: false
name: test
params: array(
0: Param(
type: bool
byRef: false
variadic: false
name: a
default: null
)
1: Param(
type: int
byRef: false
variadic: false
name: b
default: null
)
2: Param(
type: float
byRef: false
variadic: false
name: c
default: null
)
3: Param(
type: string
byRef: false
variadic: false
name: d
default: null
)
4: Param(
type: iterable
byRef: false
variadic: false
name: e
default: null
)
5: Param(
type: object
byRef: false
variadic: false
name: f
default: null
)
)
returnType: void
stmts: array(
)
)
)

View file

@ -0,0 +1,41 @@
Return and pass by ref
-----
<?php
function a(&$b) {}
function &a($b) {}
-----
array(
0: Stmt_Function(
byRef: false
name: a
params: array(
0: Param(
type: null
byRef: true
variadic: false
name: b
default: null
)
)
returnType: null
stmts: array(
)
)
1: Stmt_Function(
byRef: true
name: a
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: b
default: null
)
)
returnType: null
stmts: array(
)
)
)

View file

@ -0,0 +1,33 @@
Conditional function definition
-----
<?php
if (true) {
function A() {}
}
-----
array(
0: Stmt_If(
cond: Expr_ConstFetch(
name: Name(
parts: array(
0: true
)
)
)
stmts: array(
0: Stmt_Function(
byRef: false
name: A
params: array(
)
returnType: null
stmts: array(
)
)
)
elseifs: array(
)
else: null
)
)

View file

@ -0,0 +1,148 @@
Default values (static scalar tests)
-----
<?php
function a(
$b = null,
$c = 'foo',
$d = A::B,
$f = +1,
$g = -1.0,
$h = array(),
$i = [],
$j = ['foo'],
$k = ['foo', 'bar' => 'baz']
) {}
-----
array(
0: Stmt_Function(
byRef: false
name: a
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: b
default: Expr_ConstFetch(
name: Name(
parts: array(
0: null
)
)
)
)
1: Param(
type: null
byRef: false
variadic: false
name: c
default: Scalar_String(
value: foo
)
)
2: Param(
type: null
byRef: false
variadic: false
name: d
default: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: B
)
)
3: Param(
type: null
byRef: false
variadic: false
name: f
default: Expr_UnaryPlus(
expr: Scalar_LNumber(
value: 1
)
)
)
4: Param(
type: null
byRef: false
variadic: false
name: g
default: Expr_UnaryMinus(
expr: Scalar_DNumber(
value: 1
)
)
)
5: Param(
type: null
byRef: false
variadic: false
name: h
default: Expr_Array(
items: array(
)
)
)
6: Param(
type: null
byRef: false
variadic: false
name: i
default: Expr_Array(
items: array(
)
)
)
7: Param(
type: null
byRef: false
variadic: false
name: j
default: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_String(
value: foo
)
byRef: false
)
)
)
)
8: Param(
type: null
byRef: false
variadic: false
name: k
default: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_String(
value: foo
)
byRef: false
)
1: Expr_ArrayItem(
key: Scalar_String(
value: bar
)
value: Scalar_String(
value: baz
)
byRef: false
)
)
)
)
)
returnType: null
stmts: array(
)
)
)

View file

@ -0,0 +1,47 @@
Nullable types
-----
<?php
function test(?Foo $bar, ?string $foo) : ?Baz {
}
-----
!!php7
array(
0: Stmt_Function(
byRef: false
name: test
params: array(
0: Param(
type: NullableType(
type: Name(
parts: array(
0: Foo
)
)
)
byRef: false
variadic: false
name: bar
default: null
)
1: Param(
type: NullableType(
type: string
)
byRef: false
variadic: false
name: foo
default: null
)
)
returnType: NullableType(
type: Name(
parts: array(
0: Baz
)
)
)
stmts: array(
)
)
)

View file

@ -0,0 +1,52 @@
Return type declarations
-----
<?php
function test1() {}
function test2() : array {}
function test3() : callable {}
function test4() : Foo\Bar {}
-----
array(
0: Stmt_Function(
byRef: false
name: test1
params: array(
)
returnType: null
stmts: array(
)
)
1: Stmt_Function(
byRef: false
name: test2
params: array(
)
returnType: array
stmts: array(
)
)
2: Stmt_Function(
byRef: false
name: test3
params: array(
)
returnType: callable
stmts: array(
)
)
3: Stmt_Function(
byRef: false
name: test4
params: array(
)
returnType: Name(
parts: array(
0: Foo
1: Bar
)
)
stmts: array(
)
)
)

View file

@ -0,0 +1,51 @@
Special function variables
-----
<?php
function a() {
global $a, ${'b'}, $$c;
static $c, $d = 'e';
}
-----
array(
0: Stmt_Function(
byRef: false
name: a
params: array(
)
returnType: null
stmts: array(
0: Stmt_Global(
vars: array(
0: Expr_Variable(
name: a
)
1: Expr_Variable(
name: Scalar_String(
value: b
)
)
2: Expr_Variable(
name: Expr_Variable(
name: c
)
)
)
)
1: Stmt_Static(
vars: array(
0: Stmt_StaticVar(
name: c
default: null
)
1: Stmt_StaticVar(
name: d
default: Scalar_String(
value: e
)
)
)
)
)
)
)

View file

@ -0,0 +1,49 @@
Type hints
-----
<?php
function a($b, array $c, callable $d, E $f) {}
-----
array(
0: Stmt_Function(
byRef: false
name: a
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: b
default: null
)
1: Param(
type: array
byRef: false
variadic: false
name: c
default: null
)
2: Param(
type: callable
byRef: false
variadic: false
name: d
default: null
)
3: Param(
type: Name(
parts: array(
0: E
)
)
byRef: false
variadic: false
name: f
default: null
)
)
returnType: null
stmts: array(
)
)
)

View file

@ -0,0 +1,110 @@
Variadic functions
-----
<?php
function test($a, ... $b) {}
function test($a, &... $b) {}
function test($a, Type ... $b) {}
function test($a, Type &... $b) {}
-----
array(
0: Stmt_Function(
byRef: false
name: test
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
1: Param(
type: null
byRef: false
variadic: true
name: b
default: null
)
)
returnType: null
stmts: array(
)
)
1: Stmt_Function(
byRef: false
name: test
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
1: Param(
type: null
byRef: true
variadic: true
name: b
default: null
)
)
returnType: null
stmts: array(
)
)
2: Stmt_Function(
byRef: false
name: test
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
1: Param(
type: Name(
parts: array(
0: Type
)
)
byRef: false
variadic: true
name: b
default: null
)
)
returnType: null
stmts: array(
)
)
3: Stmt_Function(
byRef: false
name: test
params: array(
0: Param(
type: null
byRef: false
variadic: false
name: a
default: null
)
1: Param(
type: Name(
parts: array(
0: Type
)
)
byRef: true
variadic: true
name: b
default: null
)
)
returnType: null
stmts: array(
)
)
)

View file

@ -0,0 +1,27 @@
Invalid variadic function
-----
<?php
function foo(...$foo = []) {}
-----
Variadic parameter cannot have a default value from 2:24 to 2:25
array(
0: Stmt_Function(
byRef: false
name: foo
params: array(
0: Param(
type: null
byRef: false
variadic: true
name: foo
default: Expr_Array(
items: array(
)
)
)
)
returnType: null
stmts: array(
)
)
)

View file

@ -0,0 +1,280 @@
Generators (yield expression)
-----
<?php
function gen() {
// statements
yield;
yield $value;
yield $key => $value;
// expressions
$data = yield;
$data = (yield $value);
$data = (yield $key => $value);
// yield in language constructs with their own parentheses
if (yield $foo); elseif (yield $foo);
if (yield $foo): elseif (yield $foo): endif;
while (yield $foo);
do {} while (yield $foo);
switch (yield $foo) {}
die(yield $foo);
// yield in function calls
func(yield $foo);
$foo->func(yield $foo);
new Foo(yield $foo);
yield from $foo;
yield from $foo and yield from $bar;
yield from $foo + $bar;
}
-----
array(
0: Stmt_Function(
byRef: false
name: gen
params: array(
)
returnType: null
stmts: array(
0: Expr_Yield(
key: null
value: null
comments: array(
0: // statements
)
)
1: Expr_Yield(
key: null
value: Expr_Variable(
name: value
)
)
2: Expr_Yield(
key: Expr_Variable(
name: key
)
value: Expr_Variable(
name: value
)
)
3: Expr_Assign(
var: Expr_Variable(
name: data
comments: array(
0: // expressions
)
)
expr: Expr_Yield(
key: null
value: null
)
comments: array(
0: // expressions
)
)
4: Expr_Assign(
var: Expr_Variable(
name: data
)
expr: Expr_Yield(
key: null
value: Expr_Variable(
name: value
)
)
)
5: Expr_Assign(
var: Expr_Variable(
name: data
)
expr: Expr_Yield(
key: Expr_Variable(
name: key
)
value: Expr_Variable(
name: value
)
)
)
6: Stmt_If(
cond: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
stmts: array(
)
elseifs: array(
0: Stmt_ElseIf(
cond: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
stmts: array(
)
)
)
else: null
comments: array(
0: // yield in language constructs with their own parentheses
)
)
7: Stmt_If(
cond: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
stmts: array(
)
elseifs: array(
0: Stmt_ElseIf(
cond: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
stmts: array(
)
)
)
else: null
)
8: Stmt_While(
cond: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
stmts: array(
)
)
9: Stmt_Do(
cond: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
stmts: array(
)
)
10: Stmt_Switch(
cond: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
cases: array(
)
)
11: Expr_Exit(
expr: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
)
12: Expr_FuncCall(
name: Name(
parts: array(
0: func
)
comments: array(
0: // yield in function calls
)
)
args: array(
0: Arg(
value: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
byRef: false
unpack: false
)
)
comments: array(
0: // yield in function calls
)
)
13: Expr_MethodCall(
var: Expr_Variable(
name: foo
)
name: func
args: array(
0: Arg(
value: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
byRef: false
unpack: false
)
)
)
14: Expr_New(
class: Name(
parts: array(
0: Foo
)
)
args: array(
0: Arg(
value: Expr_Yield(
key: null
value: Expr_Variable(
name: foo
)
)
byRef: false
unpack: false
)
)
)
15: Expr_YieldFrom(
expr: Expr_Variable(
name: foo
)
)
16: Expr_BinaryOp_LogicalAnd(
left: Expr_YieldFrom(
expr: Expr_Variable(
name: foo
)
)
right: Expr_YieldFrom(
expr: Expr_Variable(
name: bar
)
)
)
17: Expr_YieldFrom(
expr: Expr_BinaryOp_Plus(
left: Expr_Variable(
name: foo
)
right: Expr_Variable(
name: bar
)
)
)
)
)
)

View file

@ -0,0 +1,230 @@
Yield operator precedence
-----
<?php
function gen() {
yield "a" . "b";
yield "a" or die;
yield "k" => "a" . "b";
yield "k" => "a" or die;
var_dump([yield "k" => "a" . "b"]);
yield yield "k1" => yield "k2" => "a" . "b";
yield yield "k1" => (yield "k2") => "a" . "b";
var_dump([yield "k1" => yield "k2" => "a" . "b"]);
var_dump([yield "k1" => (yield "k2") => "a" . "b"]);
}
-----
!!php7
array(
0: Stmt_Function(
byRef: false
name: gen
params: array(
)
returnType: null
stmts: array(
0: Expr_Yield(
key: null
value: Expr_BinaryOp_Concat(
left: Scalar_String(
value: a
)
right: Scalar_String(
value: b
)
)
)
1: Expr_BinaryOp_LogicalOr(
left: Expr_Yield(
key: null
value: Scalar_String(
value: a
)
)
right: Expr_Exit(
expr: null
)
)
2: Expr_Yield(
key: Scalar_String(
value: k
)
value: Expr_BinaryOp_Concat(
left: Scalar_String(
value: a
)
right: Scalar_String(
value: b
)
)
)
3: Expr_BinaryOp_LogicalOr(
left: Expr_Yield(
key: Scalar_String(
value: k
)
value: Scalar_String(
value: a
)
)
right: Expr_Exit(
expr: null
)
)
4: Expr_FuncCall(
name: Name(
parts: array(
0: var_dump
)
)
args: array(
0: Arg(
value: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Yield(
key: Scalar_String(
value: k
)
value: Expr_BinaryOp_Concat(
left: Scalar_String(
value: a
)
right: Scalar_String(
value: b
)
)
)
byRef: false
)
)
)
byRef: false
unpack: false
)
)
)
5: Expr_Yield(
key: null
value: Expr_Yield(
key: Scalar_String(
value: k1
)
value: Expr_Yield(
key: Scalar_String(
value: k2
)
value: Expr_BinaryOp_Concat(
left: Scalar_String(
value: a
)
right: Scalar_String(
value: b
)
)
)
)
)
6: Expr_Yield(
key: Expr_Yield(
key: Scalar_String(
value: k1
)
value: Expr_Yield(
key: null
value: Scalar_String(
value: k2
)
)
)
value: Expr_BinaryOp_Concat(
left: Scalar_String(
value: a
)
right: Scalar_String(
value: b
)
)
)
7: Expr_FuncCall(
name: Name(
parts: array(
0: var_dump
)
)
args: array(
0: Arg(
value: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Yield(
key: Scalar_String(
value: k1
)
value: Expr_Yield(
key: Scalar_String(
value: k2
)
value: Expr_BinaryOp_Concat(
left: Scalar_String(
value: a
)
right: Scalar_String(
value: b
)
)
)
)
byRef: false
)
)
)
byRef: false
unpack: false
)
)
)
8: Expr_FuncCall(
name: Name(
parts: array(
0: var_dump
)
)
args: array(
0: Arg(
value: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Expr_Yield(
key: Scalar_String(
value: k1
)
value: Expr_Yield(
key: null
value: Scalar_String(
value: k2
)
)
)
value: Expr_BinaryOp_Concat(
left: Scalar_String(
value: a
)
right: Scalar_String(
value: b
)
)
byRef: false
)
)
)
byRef: false
unpack: false
)
)
)
)
)
)

View file

@ -0,0 +1,48 @@
Yield with unary operator argument
-----
<?php
function gen() {
yield +1;
yield -1;
yield * -1;
}
-----
array(
0: Stmt_Function(
byRef: false
name: gen
params: array(
)
returnType: null
stmts: array(
0: Expr_Yield(
key: null
value: Expr_UnaryPlus(
expr: Scalar_LNumber(
value: 1
)
)
)
1: Expr_Yield(
key: null
value: Expr_UnaryMinus(
expr: Scalar_LNumber(
value: 1
)
)
)
2: Expr_BinaryOp_Mul(
left: Expr_Yield(
key: null
value: null
)
right: Expr_UnaryMinus(
expr: Scalar_LNumber(
value: 1
)
)
)
)
)
)

View file

@ -0,0 +1,55 @@
__halt_compiler
-----
<?php
$a;
__halt_compiler()
?>
Hallo World!
-----
array(
0: Expr_Variable(
name: a
)
1: Stmt_HaltCompiler(
remaining: Hallo World!
)
)
-----
<?php
$a;
__halt_compiler();Hallo World!
-----
array(
0: Expr_Variable(
name: a
)
1: Stmt_HaltCompiler(
remaining: Hallo World!
)
)
-----
<?php
namespace A;
$a;
__halt_compiler();
-----
array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: A
)
)
stmts: array(
0: Expr_Variable(
name: a
)
)
)
1: Stmt_HaltCompiler(
remaining:
)
)

View file

@ -0,0 +1,6 @@
Invalid __halt_compiler() syntax
-----
<?php
__halt_compiler()
-----
__HALT_COMPILER must be followed by "();" on line 2

View file

@ -0,0 +1,34 @@
Use of __HALT_COMPILER_OFFSET__ constant
-----
<?php
var_dump(__HALT_COMPILER_OFFSET__);
__halt_compiler();
Foo
-----
array(
0: Expr_FuncCall(
name: Name(
parts: array(
0: var_dump
)
)
args: array(
0: Arg(
value: Expr_ConstFetch(
name: Name(
parts: array(
0: __HALT_COMPILER_OFFSET__
)
)
)
byRef: false
unpack: false
)
)
)
1: Stmt_HaltCompiler(
remaining:
Foo
)
)

View file

@ -0,0 +1,8 @@
__halt_compiler can only be used from outermost scope
-----
<?php
if (true) {
__halt_compiler();
}
-----
__HALT_COMPILER() can only be used from the outermost scope from 3:5 to 3:19

View file

@ -0,0 +1,26 @@
Hashbang line
-----
#!/usr/bin/env php
<?php
echo "foobar";
?>
#!/usr/bin/env php
-----
array(
0: Stmt_InlineHTML(
value: #!/usr/bin/env php
)
1: Stmt_Echo(
exprs: array(
0: Scalar_String(
value: foobar
)
)
)
2: Stmt_InlineHTML(
value: #!/usr/bin/env php
)
)

View file

@ -0,0 +1,103 @@
If/Elseif/Else
-----
<?php
if ($a) {}
elseif ($b) {}
elseif ($c) {}
else {}
if ($a) {} // without else
if ($a):
elseif ($b):
elseif ($c):
else :
endif;
if ($a): endif; // without else
-----
array(
0: Stmt_If(
cond: Expr_Variable(
name: a
)
stmts: array(
)
elseifs: array(
0: Stmt_ElseIf(
cond: Expr_Variable(
name: b
)
stmts: array(
)
)
1: Stmt_ElseIf(
cond: Expr_Variable(
name: c
)
stmts: array(
)
)
)
else: Stmt_Else(
stmts: array(
)
)
)
1: Stmt_If(
cond: Expr_Variable(
name: a
)
stmts: array(
)
elseifs: array(
)
else: null
)
2: Stmt_If(
cond: Expr_Variable(
name: a
)
stmts: array(
)
elseifs: array(
0: Stmt_ElseIf(
cond: Expr_Variable(
name: b
)
stmts: array(
)
)
1: Stmt_ElseIf(
cond: Expr_Variable(
name: c
)
stmts: array(
)
)
)
else: Stmt_Else(
stmts: array(
)
)
comments: array(
0: // without else
)
)
3: Stmt_If(
cond: Expr_Variable(
name: a
)
stmts: array(
)
elseifs: array(
)
else: null
)
4: Stmt_Nop(
comments: array(
0: // without else
)
)
)

View file

@ -0,0 +1,27 @@
Inline HTML
-----
<?php
$a;
?>
B
<?php
$c;
?>
<?php
$d;
-----
array(
0: Expr_Variable(
name: a
)
1: Stmt_InlineHTML(
value: B
)
2: Expr_Variable(
name: c
)
3: Expr_Variable(
name: d
)
)

View file

@ -0,0 +1,17 @@
Do loop
-----
<?php
do {
} while ($a);
-----
array(
0: Stmt_Do(
cond: Expr_Variable(
name: a
)
stmts: array(
)
)
)

View file

@ -0,0 +1,110 @@
For loop
-----
<?php
// "classical" loop
for ($i = 0; $i < $c; ++$i) {}
// multiple expressions
for ($a, $b; $c, $d; $e, $f) {}
// infinite loop
for (;;) {}
// alternative syntax
for (;;):
endfor;
-----
array(
0: Stmt_For(
init: array(
0: Expr_Assign(
var: Expr_Variable(
name: i
)
expr: Scalar_LNumber(
value: 0
)
)
)
cond: array(
0: Expr_BinaryOp_Smaller(
left: Expr_Variable(
name: i
)
right: Expr_Variable(
name: c
)
)
)
loop: array(
0: Expr_PreInc(
var: Expr_Variable(
name: i
)
)
)
stmts: array(
)
comments: array(
0: // "classical" loop
)
)
1: Stmt_For(
init: array(
0: Expr_Variable(
name: a
)
1: Expr_Variable(
name: b
)
)
cond: array(
0: Expr_Variable(
name: c
)
1: Expr_Variable(
name: d
)
)
loop: array(
0: Expr_Variable(
name: e
)
1: Expr_Variable(
name: f
)
)
stmts: array(
)
comments: array(
0: // multiple expressions
)
)
2: Stmt_For(
init: array(
)
cond: array(
)
loop: array(
)
stmts: array(
)
comments: array(
0: // infinite loop
)
)
3: Stmt_For(
init: array(
)
cond: array(
)
loop: array(
)
stmts: array(
)
comments: array(
0: // alternative syntax
)
)
)

View file

@ -0,0 +1,164 @@
Foreach loop
-----
<?php
// foreach on variable
foreach ($a as $b) {}
foreach ($a as &$b) {}
foreach ($a as $b => $c) {}
foreach ($a as $b => &$c) {}
foreach ($a as list($a, $b)) {}
foreach ($a as $a => list($b, , $c)) {}
// foreach on expression
foreach (array() as $b) {}
// alternative syntax
foreach ($a as $b):
endforeach;
-----
array(
0: Stmt_Foreach(
expr: Expr_Variable(
name: a
)
keyVar: null
byRef: false
valueVar: Expr_Variable(
name: b
)
stmts: array(
)
comments: array(
0: // foreach on variable
)
)
1: Stmt_Foreach(
expr: Expr_Variable(
name: a
)
keyVar: null
byRef: true
valueVar: Expr_Variable(
name: b
)
stmts: array(
)
)
2: Stmt_Foreach(
expr: Expr_Variable(
name: a
)
keyVar: Expr_Variable(
name: b
)
byRef: false
valueVar: Expr_Variable(
name: c
)
stmts: array(
)
)
3: Stmt_Foreach(
expr: Expr_Variable(
name: a
)
keyVar: Expr_Variable(
name: b
)
byRef: true
valueVar: Expr_Variable(
name: c
)
stmts: array(
)
)
4: Stmt_Foreach(
expr: Expr_Variable(
name: a
)
keyVar: null
byRef: false
valueVar: Expr_List(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: a
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: b
)
byRef: false
)
)
)
stmts: array(
)
)
5: Stmt_Foreach(
expr: Expr_Variable(
name: a
)
keyVar: Expr_Variable(
name: a
)
byRef: false
valueVar: Expr_List(
items: array(
0: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: b
)
byRef: false
)
1: null
2: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: c
)
byRef: false
)
)
)
stmts: array(
)
)
6: Stmt_Foreach(
expr: Expr_Array(
items: array(
)
)
keyVar: null
byRef: false
valueVar: Expr_Variable(
name: b
)
stmts: array(
)
comments: array(
0: // foreach on expression
)
)
7: Stmt_Foreach(
expr: Expr_Variable(
name: a
)
keyVar: null
byRef: false
valueVar: Expr_Variable(
name: b
)
stmts: array(
)
comments: array(
0: // alternative syntax
)
)
)

View file

@ -0,0 +1,25 @@
While loop
-----
<?php
while ($a) {}
while ($a):
endwhile;
-----
array(
0: Stmt_While(
cond: Expr_Variable(
name: a
)
stmts: array(
)
)
1: Stmt_While(
cond: Expr_Variable(
name: a
)
stmts: array(
)
)
)

View file

@ -0,0 +1,65 @@
Try/catch with multiple classes
-----
<?php
try {
$x;
} catch (X|Y $e1) {
$y;
} catch (\A|B\C $e2) {
$z;
}
-----
!!php7
array(
0: Stmt_TryCatch(
stmts: array(
0: Expr_Variable(
name: x
)
)
catches: array(
0: Stmt_Catch(
types: array(
0: Name(
parts: array(
0: X
)
)
1: Name(
parts: array(
0: Y
)
)
)
var: e1
stmts: array(
0: Expr_Variable(
name: y
)
)
)
1: Stmt_Catch(
types: array(
0: Name_FullyQualified(
parts: array(
0: A
)
)
1: Name(
parts: array(
0: B
1: C
)
)
)
var: e2
stmts: array(
0: Expr_Variable(
name: z
)
)
)
)
finally: null
)
)

View file

@ -0,0 +1,168 @@
Aliases (use)
-----
<?php
use A\B;
use C\D as E;
use F\G as H, J;
// evil alias notation - Do Not Use!
use \A;
use \A as B;
// function and constant aliases
use function foo\bar;
use function foo\bar as baz;
use const foo\BAR;
use const foo\BAR as BAZ;
-----
array(
0: Stmt_Use(
type: TYPE_NORMAL (1)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: A
1: B
)
)
alias: B
)
)
)
1: Stmt_Use(
type: TYPE_NORMAL (1)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: C
1: D
)
)
alias: E
)
)
)
2: Stmt_Use(
type: TYPE_NORMAL (1)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: F
1: G
)
)
alias: H
)
1: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: J
)
)
alias: J
)
)
)
3: Stmt_Use(
type: TYPE_NORMAL (1)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: A
)
)
alias: A
)
)
comments: array(
0: // evil alias notation - Do Not Use!
)
)
4: Stmt_Use(
type: TYPE_NORMAL (1)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: A
)
)
alias: B
)
)
)
5: Stmt_Use(
type: TYPE_FUNCTION (2)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: foo
1: bar
)
)
alias: bar
)
)
comments: array(
0: // function and constant aliases
)
)
6: Stmt_Use(
type: TYPE_FUNCTION (2)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: foo
1: bar
)
)
alias: baz
)
)
)
7: Stmt_Use(
type: TYPE_CONSTANT (3)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: foo
1: BAR
)
)
alias: BAR
)
)
)
8: Stmt_Use(
type: TYPE_CONSTANT (3)
uses: array(
0: Stmt_UseUse(
type: TYPE_UNKNOWN (0)
name: Name(
parts: array(
0: foo
1: BAR
)
)
alias: BAZ
)
)
)
)

View file

@ -0,0 +1,42 @@
Braced namespaces
-----
<?php
namespace Foo\Bar {
foo;
}
namespace {
bar;
}
-----
array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: Foo
1: Bar
)
)
stmts: array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: foo
)
)
)
)
)
1: Stmt_Namespace(
name: null
stmts: array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: bar
)
)
)
)
)
)

View file

@ -0,0 +1,22 @@
Trailing comment after braced namespace declaration
-----
<?php
namespace Foo {}
// Comment
-----
array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: Foo
)
)
stmts: array(
)
)
1: Stmt_Nop(
comments: array(
0: // Comment
)
)
)

Some files were not shown because too many files have changed in this diff Show more