- 添加 assign_coalesce_002.phpt 测试文件验证空合并赋值功能 - 在 AstNodeType 中新增 isConstFetch 和 isAssignOp 辅助方法 - 优化 CompilerBase 中的空合并赋值编译逻辑,使用三元运算符替代 if 语句 - 修复局部变量检测和类型推断相关问题pull/1/head
parent
7292635b3d
commit
34f157871d
3 changed files with 50 additions and 3 deletions
@ -0,0 +1,39 @@ |
||||
--TEST-- |
||||
assign coalesce 002 |
||||
--FILE-- |
||||
<?php |
||||
function case1() { |
||||
$context = new ArrayObject(); |
||||
$context['session'] = 'world'; |
||||
return $context['session'] ??= 'hello'; |
||||
} |
||||
|
||||
function case2() { |
||||
$context = new ArrayObject(); |
||||
return $context['session'] ??= 'hello'; |
||||
} |
||||
|
||||
function case3() { |
||||
$context = []; |
||||
$context['session'] = 'world'; |
||||
return $context['session'] ??= 'hello'; |
||||
} |
||||
|
||||
function case4() { |
||||
$context = []; |
||||
return $context['session'] ??= 'hello'; |
||||
} |
||||
|
||||
function main() { |
||||
error_reporting(E_ERROR); |
||||
var_dump(case1()); |
||||
var_dump(case2()); |
||||
var_dump(case3()); |
||||
var_dump(case4()); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
string(5) "world" |
||||
string(5) "hello" |
||||
string(5) "world" |
||||
string(5) "hello" |
||||
Loading…
Reference in new issue