PHP插件定义类和接口

From: http://duanshaozhen.iteye.com/

插件中所谓php的接口,是通过定义类的虚函数实现的。
定义一个接口还是很方便的,我先给出一个PHP语言中的形式。
<?php
interface i_myinterface
{
    public function hello();
}
那它在扩展中的实现是这样的。
zend_class_entry *i_myinterface_ce;

static zend_function_entry i_myinterface_method[]={
    ZEND_ABSTRACT_ME(i_myinterface, hello, NULL) //注意这里的null指的是arginfo
    {NULL,NULL,NULL}
};

ZEND_MINIT_FUNCTION(test)
{  
    zend_class_entry ce;
    INIT_CLASS_ENTRY(ce, "i_myinterface", i_myinterface_method);

    i_myinterface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
    return SUCCESS;
}

From: http://duanshaozhen.iteye.com/

你可能感兴趣的:(PHP,类,插件,内核,Zend)