From 81272cf7fb2e6551689d420415ebf57c336aa114 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sat, 23 May 2026 15:23:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E5=B0=86=E5=86=85=E7=BD=AE?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E8=B0=83=E7=94=A8=E6=94=B9=E4=B8=BA=E7=AC=A6?= =?UTF-8?q?=E5=8F=B7=E8=A1=A8=E8=B0=83=E7=94=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 funcSymbols 数组存储函数符号 - 修改 shell_exec 调用为通过符号表调用 - 修改 define 函数调用为通过符号表调用 - 在 prepare 方法中初始化 shell_exec 和 define 的函数指针 --- src/Php/CompilerBase.php | 3 ++- src/Php/Translator.php | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 743ea120..5b136f6c 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -162,6 +162,7 @@ class CompilerBase extends \PhpAot\Core\Translator ]; protected array $localHeaders = []; protected array $internalFunctions = []; + protected array $funcSymbols = []; protected array $internalConstants = []; /** @@ -5182,7 +5183,7 @@ class CompilerBase extends \PhpAot\Core\Translator foreach ($expr->parts as $part) { $list[] = $this->identifierToStr($part); } - return 'php::shell_exec(php::concat({' . implode(', ', $list) . '}))'; + return 'php::call(' . $this->funcSymbols['shell_exec'] . ', { php::concat({' . implode(', ', $list) . '}) })'; } protected function parseGoto(Node\Stmt\Goto_ $v): string diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 8e215eae..957368ad 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -285,6 +285,9 @@ class Translator extends Preprocessor public function prepare(string $path): array { + $this->funcSymbols['shell_exec'] = $this->getFuncPtr('shell_exec'); + $this->funcSymbols['define'] = $this->getFuncPtr('define'); + // 根据平台检查库文件(仅在构建二进制文件时需要) if ($this->isBuildModeBin()) { foreach ($this->getPlatform()->getBuildLibraryWarnings($this->getPhpDir(), $this->getPhpxDir(), $this->buildMode) as $message) { @@ -564,7 +567,7 @@ CODE; $code .= '// register constants' . PHP_EOL; foreach ($this->constants as $name => $const) { $code .= "{$name} = {$const->value};\n"; - $code .= 'php::define(' . $this->genCharPtr($const->name, true) . ', ' . $name . ');' . PHP_EOL; + $code .= 'php::call(' . $this->funcSymbols['define'] . ', { ' . $this->genCharPtr($const->name, true) . ', ' . $name . ' });' . PHP_EOL; } $code .= '// global vars ' . PHP_EOL; foreach ($this->globalVars as $name => $type) {