fix(php): 修复对象值解析和函数参数处理问题

- 修复了对象值解析时未正确解析标识符的问题
- 为 FunctionDef 类的 argInfoList 属性添加了 PHPDoc 注释
- 在示例文件中添加了测试函数来验证参数处理功能
- 实现了对带默认值参数的正确处理逻辑
pull/1/head
韩天峰 7 months ago
parent abb5dbc6d8
commit a529ccf306
  1. 5
      examples/obj.php
  2. 2
      src/Php/CompilerBase.php
  3. 3
      src/Php/FunctionDef.php
  4. 7
      src/Php/Translator.php

@ -11,6 +11,11 @@ class Test
$this->b = $b;
}
public function testArg(int $a, int $b = 3, string $s = 'hello'): int
{
return $a + $b + strlen($s);
}
public function test()
{
return $this->a + $this->b;

@ -845,7 +845,7 @@ class CompilerBase extends \PhpAot\Core\Translator
} elseif ($this->isFuncCallExpr($right) and $this->isNameExpr($right->name)) {
$fn = $this->parseIdentifier($right->name);
if (count($right->args) === 2 and $fn === 'objval' and $this->isScalarString($right->args[1]->value)) {
$this->objects[$var] = $right->args[1]->value;
$this->objects[$var] = $this->parseIdentifier($right->args[1]->value);
$type = self::TYPE_OBJECT;
}
}

@ -6,6 +6,9 @@ class FunctionDef
{
public string $name;
public string $returnType;
/**
* @var array<ArgInfo>
*/
public array $argInfoList = [];
public int $argCountRequired = 0;
public string $params = '';

@ -600,7 +600,12 @@ class Translator extends Preprocessor
$callParams = '';
foreach ($methodDef->functionDef->argInfoList as $k => $argInfo) {
$expr = $this->convertExprFromType($argInfo->type, 'ZEND_CALL_ARG(EG(current_execute_data), ' . ($k + 1) . ')');
if ($argInfo->default) {
$argExpr = 'php::getCallArg(' . $k . ', ' . $argInfo->default . ')';
} else {
$argExpr = 'php::getCallArg(' . $k . ')';
}
$expr = $this->convertExprFromType($argInfo->type, $argExpr);
$cppCode .= $this->getIndent() . $argInfo->type . ' arg_' . $argInfo->name . ' = ' . $expr . ';' . PHP_EOL;
$callParams .= 'arg_' . $argInfo->name . ',';
}

Loading…
Cancel
Save