From fa2a1d286f9a76e8c504d3d93c8005afb9882e95 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 25 Mar 2026 19:27:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E4=BC=98=E5=8C=96=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=8C=85=E8=A3=85=E5=99=A8=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=B9=B6=E4=BF=AE=E5=A4=8D=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E8=BD=AC=E4=B9=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 简化了 CompilerBase.php 中的对象包装器逻辑,减少临时变量创建 - 为 gen_stub.php 中的 minimumPhpVersionIdCompatibility 设置默认值 PHP_80_VERSION_ID - 在 Generator/Utils.php 的 escapeString 方法中添加 C++ 三字母词序列处理 --- bin/gen_stub.php | 2 +- src/Php/CompilerBase.php | 15 ++++----------- src/Php/Generator/Utils.php | 4 +++- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/bin/gen_stub.php b/bin/gen_stub.php index 9f8ba4a7..9826d10c 100755 --- a/bin/gen_stub.php +++ b/bin/gen_stub.php @@ -4252,7 +4252,7 @@ class FileInfo { public bool $generateClassEntries = true; private bool $isUndocumentable = false; private bool $legacyArginfoGeneration = false; - private ?int $minimumPhpVersionIdCompatibility = null; + private ?int $minimumPhpVersionIdCompatibility = PHP_80_VERSION_ID; /** @param array $fileTags */ public function __construct(array $fileTags) { diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 94de34e9..352b1634 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3595,19 +3595,12 @@ class CompilerBase extends \PhpAot\Core\Translator if ($this->getVarType($id) === self::TYPE_OBJECT) { return $id; } - if (isset($this->context->objectWrappers[$id])) { - return 'php_get_object_wrap(' . $this->context->objectWrappers[$id] . ', ' . $id . ')'; - } else { - $tmpVar = $this->genTmpVarName(); - $this->addLocalVar($tmpVar, self::TYPE_OBJECT); - $this->context->beforeStmtLines[] = $this->getIndent() . $tmpVar . ' = ' . $id . ';'; - $this->context->objectWrappers[$id] = $tmpVar; - return $tmpVar; + if (!isset($this->context->objectWrappers[$id])) { + $this->context->objectWrappers[$id] = $this->addTmpVar(self::TYPE_OBJECT); } + return 'php_get_object_wrap(' . $this->context->objectWrappers[$id] . ', ' . $id . ')'; } else { - $tmpVar = $this->genTmpVarName(); - $this->context->beforeStmtLines[] = $this->getIndent() . self::TYPE_OBJECT . ' ' . $tmpVar . ' = ' . $id . ';'; - return $tmpVar; + return self::TYPE_OBJECT . '(' . $id . ')'; } } diff --git a/src/Php/Generator/Utils.php b/src/Php/Generator/Utils.php index 0b3c107a..fb3aa1a3 100644 --- a/src/Php/Generator/Utils.php +++ b/src/Php/Generator/Utils.php @@ -30,7 +30,9 @@ trait Utils protected function escapeString(string $str): string { - return addcslashes($str, "\\\"\n\r\t\v\f\0\x01..\x1f\x7f..\xff"); + $str = addcslashes($str, "\\\"\n\r\t\v\f\0\x01..\x1f\x7f..\xff"); + // C++ trigraph + return str_replace('??', '\?\?', $str); } protected function escapeBool(bool $bool): string