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) {