如何在php扩展?;中实现parent::_u构造()调用;

如何在php扩展?;中实现parent::_u构造()调用;,php,php-extension,Php,Php Extension,我想在php扩展中实现以下代码 class A{ public function __construct(){ } } class B extends A{ public function __construct(){ parent::__construct(); } } 我已经写了这些: zend_class_entry *a_class_ce, *b_class_ce; ZEND_METHOD(a_class, __constr

我想在php扩展中实现以下代码

class A{
    public function __construct(){
    }
}

class B extends A{
    public function __construct(){
        parent::__construct();
    }
}
我已经写了这些:

 zend_class_entry *a_class_ce, *b_class_ce;

    ZEND_METHOD(a_class, __construct){
    }

    ZEND_METHOD(b_class, __construct){
    }

    static zend_function_entry a_class_method[]={
            ZEND_ME(a_class, __construct, NULL, ZEND_ACC_PUBLIC)
            {NULL, NULL, NULL}
    };

    static zend_function_entry b_class_method[]={
            ZEND_ME(b_class, __construct, NULL, ZEND_ACC_PUBLIC)
            {NULL, NULL, NULL}
    };

    ZEND_MINIT_FUNCTION(test){
        zend_class_entry a_ce, b_ce;

        INIT_CLASS_ENTRY(a_ce, "A", a_class_method);
        a_class_ce = zend_register_internal_class(&a_ce TSRMLS_CC);

        INIT_CLASS_ENTRY(b_ce, "B", b_class_method);
        b_class_ce = zend_register_internal_class_ex(&b_ce, b_class_ce TSRMLS_CC);

        return SUCCESS;
    }
但我不知道如何实现parent::_uu构造()


如何实现parent::uuu构造()?

我还没有机会对其进行精确测试,但根据我在
php src
中看到的一些核心扩展的使用情况,它似乎可以工作:

void call_parent_constructor(zval* zobj)
{
    zend_class_entry* ce = zend_get_class_entry(zobj);
    zend_class_entry* parentEntry = ce->parent;

    if (parentEntry == NULL) {
        php_error(E_ERROR,"fail call_parent_constructor(): class has no parent");
        return;
    }

    zend_call_method(
        &zobj,
        parentEntry,
        &parentEntry->constructor,
        "__construct",
        sizeof("__construct")-1,
        NULL,
        0,
        NULL,
        NULL);
}
本例假设您不需要向父构造函数传递任何参数。如果您需要传递参数,请注意
zend\u call\u method()
限制您只传递0、1或2个参数


更新我已经在PHP5中测试了这种方法,它的工作原理与预期一样。

@Luke我不是PHP大师,但是。。。不,在我看来,这与Zend框架没有任何关系。@AnttiHaapala谢谢,我太离题了。