feat(php): 添加原生类和接口检查功能

- 新增 isNativeClass 方法用于检查是否为原生类
- 新增 isInterface 方法用于检查是否为接口
- 重构 addObject 方法中的对象验证逻辑
- 修改 TypedObject 使用条件判断逻辑
- 添加内部类测试用例
pull/1/head
韩天峰 3 months ago
parent 71627fd920
commit 0043fc78f8
  1. 21
      src/Php/CompilerBase.php
  2. 12
      tests/aot/class/internal-class.phpt

@ -1825,6 +1825,16 @@ class CompilerBase extends \PhpAot\Core\Translator
return Reflection::isInternalClass($name);
}
protected function isNativeClass(string $name): bool
{
return $this->hasClass($name);
}
protected function isInterface(string $name): bool
{
return $this->hasInterface($name) or $this->isInternalInterface($name);
}
protected function isAbstractClass(string $name): bool
{
if ($this->isInternalClass($name)) {
@ -2196,15 +2206,12 @@ class CompilerBase extends \PhpAot\Core\Translator
protected function addObject(string $name, string $class): void
{
// 接口、抽象类、内部类、非原生类,无法作为 TypedObject 使用
if ($this->hasInterface($class) or
$this->isInternalClass($class) or
$this->isAbstractClass($class) or
!$this->hasClass($class)) {
return;
}
// 接口、抽象类、非原生类,无法作为 TypedObject 使用
if (!$this->isInterface($class) and !$this->isAbstractClass($class) and
($this->isNativeClass($class) or $this->isInternalClass($class))) {
$this->context->objects[$name] = $class;
}
}
protected function hasVar(string $name): bool
{

@ -0,0 +1,12 @@
--TEST--
abstract class and abstract method
--FILE--
<?php
function main() {
$dt = new DateTime();
echo $dt->format('Y-m-d H:i:s');
}
?>
--EXPECTF--
%s-%s%s %s:%s:%s
Loading…
Cancel
Save