From 17e1035e21ee55907dfad0047ad98acc7b50da7e Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 11 Jun 2026 19:49:52 +0800 Subject: [PATCH] =?UTF-8?q?test(stdlib):=20=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E6=A0=87=E5=87=86=E5=BA=93=E5=87=BD=E6=95=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 测试 gettype 函数对不同数据类型的返回值 - 验证 ucfirst 函数首字母大写功能 - 检查 floor 和 ceil 数学函数的正确性 - 测试 max 和 min 函数的数值比较功能 - 验证 uniqid 函数生成唯一标识符的能力 - 测试 --- src/Php/CompilerBase.php | 8 ++++++++ src/Php/Translator.php | 10 ++++++++++ src/Php/UniversalMethodCall.php | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 614245b0..42dc99e5 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -216,6 +216,14 @@ class CompilerBase extends \PhpAot\Core\Translator 'phpx_big_float.h', 'phpx_decimal.h', 'php_aot_helper.h', + 'php_std_core.h', + 'php_std_url.h', + 'php_std_string.h', + 'php_std_misc.h', + 'php_std_array.h', + 'php_std_datetime.h', + 'php_std_fs.h', + 'php_std_math.h', ]; protected array $localHeaders = []; protected array $internalFunctions = []; diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 22d5a79a..84b9e016 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -972,6 +972,16 @@ CODE; // 生成扩展模块的源文件 $sourceFiles[] = $this->genExtension(); + // stdlib: 直接 C++ 包装的 Zend 内置函数 + $sourceFiles[] = $this->getPhpxDir() . '/src/misc/php_std_core.cpp'; + $sourceFiles[] = $this->getPhpxDir() . '/src/misc/php_std_array.cpp'; + $sourceFiles[] = $this->getPhpxDir() . '/src/misc/php_std_string.cpp'; + $sourceFiles[] = $this->getPhpxDir() . '/src/misc/php_std_url.cpp'; + $sourceFiles[] = $this->getPhpxDir() . '/src/misc/php_std_datetime.cpp'; + $sourceFiles[] = $this->getPhpxDir() . '/src/misc/php_std_fs.cpp'; + $sourceFiles[] = $this->getPhpxDir() . '/src/misc/php_std_math.cpp'; + $sourceFiles[] = $this->getPhpxDir() . '/src/misc/php_std_misc.cpp'; + // embed 需要 main 函数,以及 cli 的内置函数定义 if ($this->isBuildModeBin()) { $sourceFiles[] = $this->getPhpxDir() . '/src/misc/main.cc'; diff --git a/src/Php/UniversalMethodCall.php b/src/Php/UniversalMethodCall.php index 6e20f390..0bb75f0e 100644 --- a/src/Php/UniversalMethodCall.php +++ b/src/Php/UniversalMethodCall.php @@ -90,7 +90,7 @@ trait UniversalMethodCall 'trim' => ['handler' => 'php_fn', 'fn' => 'trim', 'return_type' => CompilerBase::TYPE_STR, 'min_args' => 0, 'max_args' => 2], 'lTrim' => ['handler' => 'php_fn', 'fn' => 'ltrim', 'return_type' => CompilerBase::TYPE_STR, 'min_args' => 0, 'max_args' => 1], 'rTrim' => ['handler' => 'php_fn', 'fn' => 'rtrim', 'return_type' => CompilerBase::TYPE_STR, 'min_args' => 0, 'max_args' => 1], - 'parseStr' => ['handler' => 'cpp_fn', 'fn' => 'php::fn::parse_str', 'return_type' => CompilerBase::TYPE_ARRAY, 'min_args' => 0, 'max_args' => 0], + 'parseStr' => ['handler' => 'cpp_fn', 'fn' => 'php::std::parse_str', 'return_type' => CompilerBase::TYPE_ARRAY, 'min_args' => 0, 'max_args' => 0], 'parseUrl' => ['handler' => 'php_fn', 'fn' => 'parse_url', 'return_type' => CompilerBase::TYPE_VAR, 'min_args' => 0, 'max_args' => 1], 'contains' => ['handler' => 'php_fn', 'fn' => 'str_contains', 'return_type' => CompilerBase::TYPE_BOOL, 'min_args' => 1, 'max_args' => 1], 'incr' => ['handler' => 'php_fn', 'fn' => 'str_increment', 'return_type' => CompilerBase::TYPE_STR, 'min_args' => 0, 'max_args' => 0],