test(const): 添加类常量默认值测试用例

- 添加了类常量默认值从 self::CV 获取的测试用例
- 测试静态方法和实例方法中使用类常量作为参数默认值
- 验证了函数调用时传入不同参数的输出结果
- 修复了类常量默认值非字符串类型时的导出问题
- 确保默认值能正确转换为字符串格式进行显示
pull/1/head
韩天峰 2 months ago
parent 881c6dbe45
commit d1c4e365b1
  1. 3
      src/gen_stub.php
  2. 33
      tests/aot/const/004.phpt

@ -4930,6 +4930,9 @@ function parseFunctionLike(
if ($param->default instanceof Expr\ClassConstFetch && $param->default->class->toLowerString() === "self") {
$defaultValue = getTranslator()->getClassConstValue($func, $name->className->name, $param->default->name->name);
if (!is_string($defaultValue)) {
$defaultValue = var_export($defaultValue, true);
}
} else {
$defaultValue = $param->default ? $prettyPrinter->prettyPrintExpr($param->default) : null;
}

@ -0,0 +1,33 @@
--TEST--
class const default value from self::CV
--FILE--
<?php
class Test
{
const CV = 1;
public static function aaa(int $v = self::CV): void
{
var_dump($v);
}
public function bbb(int $v = self::CV): void
{
var_dump($v);
}
}
function main(): void
{
Test::aaa();
Test::aaa(999);
$t = new Test();
$t->bbb();
$t->bbb(888);
}
?>
--EXPECT--
int(1)
int(999)
int(1)
int(888)
Loading…
Cancel
Save