refactor(php): 优化对象创建逻辑

- 将 object_properties_init 调用移到 php_std_create_object 函数中
- 重写 php_get_create_object_fn 函数返回 php_std_create_object
- 格式化 php_get_method 函数参数以提高可读性
- 从 Translator.php 中移除重复的对象属性初始化代码
- 简化了对象创建流程并提高了代码复用性
pull/1/head
韩天峰 5 months ago
parent cc1131f455
commit afbdf0fcdb
  1. 1
      src/Php/Translator.php
  2. 15
      src/cpp/php_aot_helper.h

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

@ -5,7 +5,10 @@
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 {
@ -13,13 +16,19 @@ struct Scope {
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;
}

Loading…
Cancel
Save