refactor(php): 优化对象包装器处理逻辑并修复字符串转义问题

- 简化了 CompilerBase.php 中的对象包装器逻辑,减少临时变量创建
- 为 gen_stub.php 中的 minimumPhpVersionIdCompatibility 设置默认值 PHP_80_VERSION_ID
- 在 Generator/Utils.php 的 escapeString 方法中添加 C++ 三字母词序列处理
pull/1/head
韩天峰 5 months ago
parent 2838053e4f
commit fa2a1d286f
  1. 2
      bin/gen_stub.php
  2. 15
      src/Php/CompilerBase.php
  3. 4
      src/Php/Generator/Utils.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<int, DocCommentTag> $fileTags */
public function __construct(array $fileTags) {

@ -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 . ')';
}
}

@ -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

Loading…
Cancel
Save