为PHP 5.4编写C++扩展,示例代码已过时

Ita*_*vka 9 php php-extension php-internals

我正在尝试为php5.4编写一个扩展,它基本上包含了一个非常简单的CPP类.

这是出于教育目的.

我发现在php5.4中这样做的方法已经从php5.3改变了

我在哪里可以找到有关如何操作的文档?或者甚至更好,代码示例,任何其他扩展,包括CPP类并在php5.4中工作

例如,过去的工作,不再是.摘自http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/

zend_object_value car_create_handler(zend_class_entry *type TSRMLS_DC)
{
    zval *tmp;
    zend_object_value retval;

    car_object *obj = (car_object *)emalloc(sizeof(car_object));
    memset(obj, 0, sizeof(car_object));
    obj->std.ce = type;

    ALLOC_HASHTABLE(obj->std.properties);
    zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
    zend_hash_copy(obj->std.properties, &type->default_properties,
        (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));

    retval.handle = zend_objects_store_put(obj, NULL,
        car_free_storage, NULL TSRMLS_CC);
    retval.handlers = &car_object_handlers;

    return retval;
}
Run Code Online (Sandbox Code Playgroud)

该行将 zend_hash_copy(obj->std.properties, &type->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); 失败,因为结构实例type(忘记它的定义)不再具有该成员default_properties

Ian*_*ory 6

PHP维基页面上的信息有帮助吗?

具体来说,为了解决您的zend_hash_copy(obj->std.properties, &type->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));示例,他们建议如下:

#if PHP_VERSION_ID < 50399
    zend_hash_copy(tobj->std.properties, &(class_type->default_properties),
        (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*));
#else
    object_properties_init(&tobj->std, class_type);
#endif
Run Code Online (Sandbox Code Playgroud)