开发环境设置见《用vc 2008编译php扩展》。
写一个扩展最基本的就是编写函数。我这里是用skel生成了一个algorithm的扩展的骨架。
php扩展中的函数用PHP_FUNCTION宏定义。首先在.h文件中写一个定义,如skel生成的代码为例:PHP_FUNCTION(confirm_algorithm_compiled);
然后在.c文件中写函数的实现。
PHP_FUNCTION(confirm_algorithm_compiled)
{
//…
}
这和传统的C编程很像。括号内就是函数的名字。这里没有参数列表,函数的参数是通过其他途径获取的。然后,还需要在扩展的函数入口表里添加一条:PHP_FE(confirm_algorithm_compiled, NULL)。这样在php里才能找到这个函数。这里FE应该就是function entry的缩写。
zend_function_entry algorithm_functions[] = {
PHP_FE(confirm_algorithm_compiled, NULL)
{NULL, NULL, NULL} /* Must be the last line in algorithm_functions[] */
};
这里的{NULL, NULL, NULL}的作用如skel生成的代码中的注释所说,是函数入口表的结束标志。
学习中……