hello.c
zend_function_entry hello_functions[] = {
    PHP_FE(confirm_hello_compiled,  NULL)       /* 这里添加一行 */
    {NULL, NULL, NULL}  /* Must be the last line in hello_functions[] */
};
PHP_FUNCTION(confirm_hello_compiled) 
{// 这里写函数体
}
要实现的函数原型其实都一个样,用宏PHP_FUNCTION来包装了一下,另外呢,在hello_functions里面添加了一行信息,表示你这个模块中有这个函数了。
那么都是一样的函数原型,如何区分返回值与参数呢?
我给一个例子:
复制代码 代码如下:
PHP_FUNCTION(hello_strdiff)
{
    char *r1 = NULL, *r2 = NULL;
    int n = 0, m = 0;
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &r1, &n, &r2, &m) == FAILURE) {
        return;
    }
    while(n && m && *r1 == *r2) {
        r1++;
        r2++;
        n--;
        m--;
    }
    if(n == 0) RETURN_LONG(m);
    if(m == 0) RETURN_LONG(n);
    int d[n+1][m+1];
    int cost;
    int i,j;
    for(i = 0; i <= n; i++) d[i][0] = i;
    for(j = 0; j <= m; j++) d[0][j] = j;
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= m; j++) {
            if(r1[i-1] == r2[j-1]) cost = 0;
            else cost = 1;
            int a = MIN(d[i-1][j]+1,d[i][j-1]+1);
            a = MIN(a, d[i-1][j-1]+cost);
            d[i][j] = a;
        }
    }
    RETURN_LONG(d[n][m]);
}
这是一个求两个字符串差异度的算法,输入参数两个字符串,返回整型。
参数的传递看这里
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &r1, &n, &r2, &m)
把这个当成是scanf来理解好了。
类型说明见下表:
Boolean   
b   
zend_bool    
Long   
l   
long    
Double   
d   
double    
String   
s   
char*, int    
Resource   
r   
zval*    
Array   
a   
zval*    
Object   
o   
zval*    
zval   
z   
zval*    
