feat(compiler): 添加对 any 函数的支持

- 在编译器中实现 any 函数的解析和处理逻辑
- 添加对 var 类型常量的支持
- 扩展测试用例以验证 any 函数的功能
pull/1/head
韩天峰 7 months ago
parent 37d0172164
commit 11828d3b5a
  1. 6
      src/Php/CompilerBase.php
  2. 1
      src/Php/Constants.php
  3. 13
      tests/aot/any.phpt

@ -866,6 +866,12 @@ class CompilerBase extends \PhpAot\Core\Translator
if (count($right->args) === 2 and $fn === 'objval' and $this->isScalarString($right->args[1]->value)) {
$this->objects[$var] = $this->parseIdentifier($right->args[1]->value);
$type = self::TYPE_OBJECT;
} elseif (count($right->args) === 1 and $fn === 'any') {
$type = self::TYPE_VAR;
if (!$this->hasVar($var)) {
$this->addLocalVar($var, $type);
}
return $var . ' = ' . $this->parseIdentifier($right->args[0]->value);
}
}

@ -34,6 +34,7 @@ class Constants
'int',
'new',
'null',
'var',
'or',
'and',
'private',

@ -0,0 +1,13 @@
--TEST--
any
--FILE--
<?php
function main()
{
$a = any(10);
$b = any(4);
echo var_dump($a/$b);
}
?>
--EXPECT--
float(2.5)
Loading…
Cancel
Save