- 在编译器中引入SyntaxError异常类用于处理PHP语法错误 - 修改预处理器捕获PHP解析错误并转换为SyntaxError异常 - 实现类常量重复定义的检测逻辑并抛出致命错误 - 添加多个测试用例验证类常量相关错误场景 - 更新编译器跳过包含语法错误的文件处理流程pull/1/head
parent
d90bf8a5fd
commit
a6826d5fd0
7 changed files with 69 additions and 2 deletions
@ -0,0 +1,8 @@ |
||||
<?php |
||||
|
||||
namespace PhpAot\Php; |
||||
|
||||
class SyntaxError extends \RuntimeException |
||||
{ |
||||
|
||||
} |
||||
@ -0,0 +1,18 @@ |
||||
--TEST-- |
||||
Error case: duplicate class constant definition |
||||
--SKIPIF-- |
||||
<?php die('skip, failed at compile time'); ?> |
||||
--FILE-- |
||||
<?php |
||||
class myclass |
||||
{ |
||||
const myConst = "hello"; |
||||
const myConst = "hello again"; |
||||
} |
||||
|
||||
function main() { |
||||
|
||||
} |
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: Cannot redefine class constant myclass::myConst in %s on line 5 |
||||
@ -0,0 +1,13 @@ |
||||
--TEST-- |
||||
Error case: class constant as an array |
||||
--FILE-- |
||||
<?php |
||||
class myclass |
||||
{ |
||||
const myConst = array(); |
||||
} |
||||
function main() { |
||||
|
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
@ -0,0 +1,16 @@ |
||||
--TEST-- |
||||
Error case: class constant as an encapsed containing a variable |
||||
--SKIPIF-- |
||||
<?php die('skip, failed at compile time'); ?> |
||||
--FILE-- |
||||
<?php |
||||
class myclass |
||||
{ |
||||
const myConst = "$myVar"; |
||||
} |
||||
function main() { |
||||
|
||||
} |
||||
?> |
||||
--EXPECTF-- |
||||
Fatal error: Constant expression contains invalid operations in %s on line %d |
||||
Loading…
Reference in new issue