首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建PHP扩展

创建PHP扩展
EN

Stack Overflow用户
提问于 2015-10-26 21:22:20
回答 1查看 415关注 0票数 0

尝试创建简单的Hello World PHP扩展,根据manual

config.m4

代码语言:javascript
复制
PHP_ARG_ENABLE(hello, whether to enable Hello
World support,
[ --enable-hello   Enable Hello World support])
if test "$PHP_HELLO" = "yes"; then
  AC_DEFINE(HAVE_HELLO, 1, [Whether you have Hello World])
  PHP_NEW_EXTENSION(hello, hello.c, $ext_shared)
fi

hello.h

代码语言:javascript
复制
#ifndef PHP_HELLO_H
#define PHP_HELLO_H 1
#define PHP_HELLO_WORLD_VERSION "1.0"
#define PHP_HELLO_WORLD_EXTNAME "hello"

PHP_FUNCTION(hello_world);

extern zend_module_entry hello_module_entry;
#define phpext_hello_ptr &hello_module_entry

#endif

hello.c

代码语言:javascript
复制
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "hello.h"

static function_entry hello_functions[] = {
    PHP_FE(hello_world, NULL)
    {NULL, NULL, NULL}
};

zend_module_entry hello_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
    STANDARD_MODULE_HEADER,
#endif
    PHP_HELLO_WORLD_EXTNAME,
    hello_functions,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
#if ZEND_MODULE_API_NO >= 20010901
    PHP_HELLO_WORLD_VERSION,
#endif
    STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_HELLO
ZEND_GET_MODULE(hello)
#endif

PHP_FUNCTION(hello_world)
{
    RETURN_STRING("Hello World", 1);
}

make抛出错误:

代码语言:javascript
复制
/bin/bash /home/ggg/cpp/php/libtool --mode=compile cc  -I. -I/home/ggg/cpp/php -DPHP_ATOM_INC -I/home/ggg/cpp/php/include -I/home/ggg/cpp/php/main -I/home/ggg/cpp/php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/ggg/cpp/php/hello.c -o hello.lo 
libtool: compile:  cc -I. -I/home/ggg/cpp/php -DPHP_ATOM_INC -I/home/ggg/cpp/php/include -I/home/ggg/cpp/php/main -I/home/ggg/cpp/php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/ggg/cpp/php/hello.c  -fPIC -DPIC -o .libs/hello.o
/home/ggg/cpp/php/hello.c:8:8: error: unknown type name 'function_entry'
 static function_entry hello_functions[] = {
        ^
/home/ggg/cpp/php/hello.c:9:5: warning: braces around scalar initializer
     PHP_FE(hello_world, NULL)
     ^
/home/ggg/cpp/php/hello.c:9:5: warning: (near initialization for 'hello_functions[0]')
/home/ggg/cpp/php/hello.c:9:5: warning: initialization makes integer from pointer without a cast
/home/ggg/cpp/php/hello.c:9:5: warning: (near initialization for 'hello_functions[0]')
/home/ggg/cpp/php/hello.c:9:5: error: initializer element is not computable at load time
/home/ggg/cpp/php/hello.c:9:5: error: (near initialization for 'hello_functions[0]')
/home/ggg/cpp/php/hello.c:9:5: warning: excess elements in scalar initializer
/home/ggg/cpp/php/hello.c:9:5: warning: (near initialization for 'hello_functions[0]')
/home/ggg/cpp/php/hello.c:9:5: warning: excess elements in scalar initializer
/home/ggg/cpp/php/hello.c:9:5: warning: (near initialization for 'hello_functions[0]')
In file included from /usr/include/php5/main/php.h:40:0,
                 from /home/ggg/cpp/php/hello.c:5:
/usr/include/php5/Zend/zend_API.h:71:129: warning: excess elements in scalar initializer
 #define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
                                                                                                                                 ^
/usr/include/php5/Zend/zend_API.h:77:38: note: in expansion of macro 'ZEND_FENTRY'
 #define ZEND_FE(name, arg_info)      ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
                                      ^
/usr/include/php5/main/php.h:353:18: note: in expansion of macro 'ZEND_FE'
 #define PHP_FE   ZEND_FE
                  ^
/home/ggg/cpp/php/hello.c:9:5: note: in expansion of macro 'PHP_FE'
     PHP_FE(hello_world, NULL)
     ^
/usr/include/php5/Zend/zend_API.h:71:129: warning: (near initialization for 'hello_functions[0]')
 #define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
                                                                                                                                 ^
/usr/include/php5/Zend/zend_API.h:77:38: note: in expansion of macro 'ZEND_FENTRY'
 #define ZEND_FE(name, arg_info)      ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
                                      ^
/usr/include/php5/main/php.h:353:18: note: in expansion of macro 'ZEND_FE'
 #define PHP_FE   ZEND_FE
                  ^
/home/ggg/cpp/php/hello.c:9:5: note: in expansion of macro 'PHP_FE'
     PHP_FE(hello_world, NULL)
     ^
/usr/include/php5/Zend/zend_API.h:71:129: warning: excess elements in scalar initializer
 #define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
                                                                                                                                 ^
/usr/include/php5/Zend/zend_API.h:77:38: note: in expansion of macro 'ZEND_FENTRY'
 #define ZEND_FE(name, arg_info)      ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
                                      ^
/usr/include/php5/main/php.h:353:18: note: in expansion of macro 'ZEND_FE'
 #define PHP_FE   ZEND_FE
                  ^
/home/ggg/cpp/php/hello.c:9:5: note: in expansion of macro 'PHP_FE'
     PHP_FE(hello_world, NULL)
     ^
/usr/include/php5/Zend/zend_API.h:71:129: warning: (near initialization for 'hello_functions[0]')
 #define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
                                                                                                                                 ^
/usr/include/php5/Zend/zend_API.h:77:38: note: in expansion of macro 'ZEND_FENTRY'
 #define ZEND_FE(name, arg_info)      ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
                                      ^
/usr/include/php5/main/php.h:353:18: note: in expansion of macro 'ZEND_FE'
 #define PHP_FE   ZEND_FE
                  ^
/home/ggg/cpp/php/hello.c:9:5: note: in expansion of macro 'PHP_FE'
     PHP_FE(hello_world, NULL)
     ^
/home/ggg/cpp/php/hello.c:10:5: warning: braces around scalar initializer
     {NULL, NULL, NULL}
     ^
/home/ggg/cpp/php/hello.c:10:5: warning: (near initialization for 'hello_functions[1]')
/home/ggg/cpp/php/hello.c:10:5: warning: initialization makes integer from pointer without a cast
/home/ggg/cpp/php/hello.c:10:5: warning: (near initialization for 'hello_functions[1]')
/home/ggg/cpp/php/hello.c:10:5: warning: excess elements in scalar initializer
/home/ggg/cpp/php/hello.c:10:5: warning: (near initialization for 'hello_functions[1]')
/home/ggg/cpp/php/hello.c:10:5: warning: excess elements in scalar initializer
/home/ggg/cpp/php/hello.c:10:5: warning: (near initialization for 'hello_functions[1]')
/home/ggg/cpp/php/hello.c:18:5: warning: initialization from incompatible pointer type
     hello_functions,
     ^
/home/ggg/cpp/php/hello.c:18:5: warning: (near initialization for 'hello_module_entry.functions')
Makefile:180: recipe for target 'hello.lo' failed
make: *** [hello.lo] Error 1
EN

回答 1

Stack Overflow用户

发布于 2016-11-17 15:23:58

我已经尝试了教程,但在运行make时遇到错误。然后,我发现function_entry不适用于PHP5.4或5.5。我用谷歌搜索了一下,发现:如果我用zend_function_entry代替function_entry,问题就解决了。它对我来说工作得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33346850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档