diff --git a/docs/NATIVE_CLASS_OBJECT.md b/docs/NATIVE_CLASS_OBJECT.md index 9004b31f..483926f5 100644 --- a/docs/NATIVE_CLASS_OBJECT.md +++ b/docs/NATIVE_CLASS_OBJECT.md @@ -39,6 +39,11 @@ Native Class Object 初版不追求以下能力: - 完整兼容 PHP 对象的析构时机和垃圾回收行为。 - 在无法静态证明安全时自动降级为 ZendVM Object。 +`new (表达式)()` 始终属于 PHP 的动态类名语法。Native Class 分支不会为了 +`new (NativeClass::class)()` 等写法额外求值、识别或增加专用诊断;这种动态创建行为 +不在 Native Class 的工作范围内。Native Object 只能通过源码中静态可解析的 +`new NativeClass(...)` 创建。 + ## 4. 显式声明 建议使用专用注解,暂定为: diff --git a/src/CompilerBase.php b/src/CompilerBase.php index 443efba4..afd92111 100644 --- a/src/CompilerBase.php +++ b/src/CompilerBase.php @@ -3780,13 +3780,13 @@ class CompilerBase implements PropertyAccessContext if ($nativeCtor === false) { $this->fatalError($expr, "Native constructor `{$className}::__construct()` cannot be resolved"); } - $args = $expr->args === [] + $nativeArgs = $expr->args === [] ? '' : ', ' . $this->parseNativeCallArgs($expr->args, $nativeCtor); return 'php::nativeConstruct<' . $cppClass . '>(' . $descriptor . ', [&](auto &this_) { ' . $this->getNativeObjectInitializerName($className) . '(this_); ' - . self::PREFIX . $nativeCtor . '(this_' . $args . '); })'; + . self::PREFIX . $nativeCtor . '(this_' . $nativeArgs . '); })'; } $cePtr = $this->getClassEntryPtr($className); }