- 实现了引用赋值功能,支持变量间的引用传递 - 添加了列表赋值解析逻辑,支持数组解构赋值操作 - 新增 isAssignExpr 方法用于判断赋值表达式类型 - 重构了赋值相关的编译逻辑,提高代码可读性 - 添加了多个测试用例验证引用和列表赋值功能 - 修复了动态调用中的参数展开问题pull/1/head v0.0.5
parent
95e7b5f6e4
commit
36cf7dbf16
7 changed files with 372 additions and 54 deletions
@ -0,0 +1,91 @@ |
||||
--TEST-- |
||||
class extends |
||||
--FILE-- |
||||
<?php |
||||
class Foo extends ArrayObject { |
||||
|
||||
} |
||||
|
||||
class A extends Foo |
||||
{ |
||||
public function __construct() |
||||
{ |
||||
echo "A::__construct()\n"; |
||||
} |
||||
} |
||||
|
||||
class B extends A |
||||
{ |
||||
public function __construct() |
||||
{ |
||||
echo "B::__construct()\n"; |
||||
parent::__construct(); |
||||
} |
||||
|
||||
|
||||
public function foo() |
||||
{ |
||||
$this->bar2(); |
||||
} |
||||
|
||||
function bar2() |
||||
{ |
||||
var_dump(__METHOD__); |
||||
} |
||||
} |
||||
|
||||
class C extends B { |
||||
public function __construct() |
||||
{ |
||||
echo "C::__construct()\n"; |
||||
parent::__construct(); |
||||
} |
||||
} |
||||
|
||||
function foo_test($a, $b, $c) { |
||||
return 1; |
||||
} |
||||
|
||||
function foo2(): void |
||||
{ |
||||
var_dump(__FUNCTION__); |
||||
return; |
||||
var_dump(__FUNCTION__); |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
var_dump(foo_test(1, 2, 3)); |
||||
$o = new B; |
||||
$o->foo(); |
||||
|
||||
$c = new C; |
||||
$c->offsetSet(0, 1); |
||||
$c->offsetSet(1, 2); |
||||
var_dump($c); |
||||
var_dump($c->foo()); |
||||
|
||||
foo2(); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
int(1) |
||||
B::__construct() |
||||
A::__construct() |
||||
string(7) "B::bar2" |
||||
C::__construct() |
||||
B::__construct() |
||||
A::__construct() |
||||
object(C)#2 (1) { |
||||
["storage":"ArrayObject":private]=> |
||||
array(2) { |
||||
[0]=> |
||||
int(1) |
||||
[1]=> |
||||
int(2) |
||||
} |
||||
} |
||||
string(7) "B::bar2" |
||||
NULL |
||||
string(4) "foo2" |
||||
|
||||
@ -0,0 +1,27 @@ |
||||
--TEST-- |
||||
named args |
||||
--FILE-- |
||||
<?php |
||||
function main() |
||||
{ |
||||
$array = [1, 3, 5]; |
||||
$push = [12, 33, 99]; |
||||
array_push($array, ...$push); |
||||
var_dump($array); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
array(6) { |
||||
[0]=> |
||||
int(1) |
||||
[1]=> |
||||
int(3) |
||||
[2]=> |
||||
int(5) |
||||
[3]=> |
||||
int(12) |
||||
[4]=> |
||||
int(33) |
||||
[5]=> |
||||
int(99) |
||||
} |
||||
@ -0,0 +1,43 @@ |
||||
--TEST-- |
||||
ref 003 |
||||
--FILE-- |
||||
<?php |
||||
function main() |
||||
{ |
||||
$a = [1, 2, 3]; |
||||
$c = $d = $e = &$a; |
||||
|
||||
$e[] = 5; |
||||
|
||||
var_dump($c); |
||||
var_dump($d); |
||||
var_dump($e); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
array(3) { |
||||
[0]=> |
||||
int(1) |
||||
[1]=> |
||||
int(2) |
||||
[2]=> |
||||
int(3) |
||||
} |
||||
array(3) { |
||||
[0]=> |
||||
int(1) |
||||
[1]=> |
||||
int(2) |
||||
[2]=> |
||||
int(3) |
||||
} |
||||
array(4) { |
||||
[0]=> |
||||
int(1) |
||||
[1]=> |
||||
int(2) |
||||
[2]=> |
||||
int(3) |
||||
[3]=> |
||||
int(5) |
||||
} |
||||
@ -0,0 +1,39 @@ |
||||
--TEST-- |
||||
ref 004 |
||||
--FILE-- |
||||
<?php |
||||
function main() |
||||
{ |
||||
$a = [1, 2, 3]; |
||||
$b = [4, 5]; |
||||
$a[] = &$b; |
||||
var_dump($a); |
||||
|
||||
$a[3][] = 10; |
||||
var_dump($b); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
array(4) { |
||||
[0]=> |
||||
int(1) |
||||
[1]=> |
||||
int(2) |
||||
[2]=> |
||||
int(3) |
||||
[3]=> |
||||
&array(2) { |
||||
[0]=> |
||||
int(4) |
||||
[1]=> |
||||
int(5) |
||||
} |
||||
} |
||||
array(3) { |
||||
[0]=> |
||||
int(4) |
||||
[1]=> |
||||
int(5) |
||||
[2]=> |
||||
int(10) |
||||
} |
||||
Loading…
Reference in new issue