PHP扩展开发(4)
这里特别感谢laruence(鸟哥)开源的yaf扩展,解决困扰我多时的多类问题,还在看他的代码学习中,这里是对多类写法学习的一个阶段总结。
#define SIMPLE_STARTUP (module) ZEND_MODULE_STARTUP_N(simple_##module)(INIT_FUNC_ARGS_PASSTHRU ) #define SIMPLE_MINIT_FUNCTION (module) ZEND_MINIT_FUNCTION(simple_##module)
#ifndef _SIMPLE_UTIL_H_ #define _SIMPLE_UTIL_H_ extern zend_class_entry *simple_util_ce; SIMPLE_MINIT_FUNCTION(util); #endif
#ifdef HAVE_CONFIG_H #include "config.php" #endif #include "php.h" #include "php_ini.h" #include "Zend/zend_interfaces.h" #include "php_simple.h" #include "simple_util.h" //这里是定义静态类 static zend_class_entry *simple_util_ce; /** {{{ ARG_INFO */ ZEND_BEGIN_ARG_INFO_EX(simple_util_void_arginfo, 0, 0, 0) ZEND_END_ARG_INFO() /* }}} */ PHP_METHOD(simple_util, read) { RETURN_STRING("这里返回函数结果" , 1); } zend_function_entry simple_util_methods[] = { PHP_ME(simple_util, read, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC ) { NULL, NULL, NULL } }; //相当于把多个扩展合在一起,每个类各自ZEND_MINIT_FUNCTION SIMPLE_MINIT_FUNCTION(util) { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "Util" , simple_util_methods); simple_util_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); return SUCCESS; }
PHP_MINIT_FUNCTION(boxun) { REGISTER_INI_ENTRIES(); SIMPLE_STARTUP(util); return SUCCESS; }