From afbdf0fcdb3490601f68bf054f8552988baa545d Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 8 Apr 2026 10:28:49 +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=88=9B=E5=BB=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 object_properties_init 调用移到 php_std_create_object 函数中 - 重写 php_get_create_object_fn 函数返回 php_std_create_object - 格式化 php_get_method 函数参数以提高可读性 - 从 Translator.php 中移除重复的对象属性初始化代码 - 简化了对象创建流程并提高了代码复用性 --- src/Php/Translator.php | 1 - src/cpp/php_aot_helper.h | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 29a3af34..dc2d021b 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -524,7 +524,6 @@ class Translator extends Preprocessor $code .= "{$ce}->create_object = [](zend_class_entry *class_type) -> zend_object* {\n"; $code .= $classDef->ctorInit; $code .= "auto obj = create_object_{$className}(class_type);\n"; - $code .= "object_properties_init(obj, class_type);\n"; foreach ($classDef->properties as $property) { $fullPropName = $classDef->getNamespacedName() . '::' . $property->name; if (isset($this->defaultPropertyList[$fullPropName])) { diff --git a/src/cpp/php_aot_helper.h b/src/cpp/php_aot_helper.h index eb849455..933b68e0 100644 --- a/src/cpp/php_aot_helper.h +++ b/src/cpp/php_aot_helper.h @@ -5,21 +5,30 @@ extern zend_class_entry *php_get_class(int class_id, const php::Str &class_name); extern zend_function *php_get_func(int func_id, const php::Str &func_name); -extern zend_function *php_get_method(int func_id, const php::Str &method_name, int class_id, const php::Str &class_name); +extern zend_function *php_get_method(int func_id, + const php::Str &method_name, + int class_id, + const php::Str &class_name); extern uint32_t php_get_prop(int prop_id, const php::Str &prop_name, int class_id, const php::Str &class_name); namespace php { struct Scope { - zend_class_entry *ce; - zend_execute_data *frame; -}; + zend_class_entry *ce; + zend_execute_data *frame; }; +}; // namespace php extern const char *php_get_called_class(php::Object &this_); extern zend_class_entry *php_get_called_ce(php::Object &this_); extern php::Scope php_switch_scope(php::Object &this_); extern void php_restore_scope(php::Scope &ori_scope); +static inline auto php_std_create_object(zend_class_entry *ce) { + auto obj = zend_objects_new(ce); + object_properties_init(obj, ce); + return obj; +} + static inline auto php_get_create_object_fn(zend_class_entry *ce) { - return ce->create_object ? ce->create_object : zend_objects_new; + return ce->create_object ? ce->create_object : php_std_create_object; }